"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/src/gui-qt/mainwindow.cpp" (12 May 2020, 82456 Bytes) of package /windows/www/highlight-3.57-x64.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "mainwindow.cpp": 3.56_vs_3.57.

    1 /***************************************************************************
    2                                mainwindow.cpp
    3                              -------------------
    4     begin                : Mo 16.03.2009
    5     copyright            : (C) 2009-2020 by Andre Simon
    6     email                : a.simon@mailbox.org
    7  ***************************************************************************/
    8 
    9 /*
   10 This file is part of Highlight.
   11 
   12 Highlight is free software: you can redistribute it and/or modify
   13 it under the terms of the GNU General Public License as published by
   14 the Free Software Foundation, either version 3 of the License, or
   15 (at your option) any later version.
   16 
   17 Highlight is distributed in the hope that it will be useful,
   18 but WITHOUT ANY WARRANTY; without even the implied warranty of
   19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   20 GNU General Public License for more details.
   21 
   22 You should have received a copy of the GNU General Public License
   23 along with Highlight.  If not, see <http://www.gnu.org/licenses/>.
   24 */
   25 
   26 #include <memory>
   27 #include <algorithm>
   28 
   29 #include <Diluculum/LuaState.hpp>
   30 
   31 #include "mainwindow.h"
   32 #include "ui_mainwindow.h"
   33 #include "version.h"
   34 #include "showtextfile.h"
   35 
   36 #include "io_report.h"
   37 #include "syntax_chooser.h"
   38 
   39 #ifdef Q_OS_WIN
   40 #include <windows.h>
   41 #endif
   42 //#include <QDebug>
   43 
   44 MainWindow::MainWindow(QWidget *parent)
   45     : QMainWindow(parent), ui(new Ui::MainWindowClass), oldThemeIndex(0), getDataFromCP(false), runFirstTime(true)
   46 {
   47 
   48     ui->setupUi(this);
   49     this->setWindowTitle(QString("Highlight %1").arg( HIGHLIGHT_VERSION));
   50 
   51     // Read file open filter
   52     QFile  filterDef(getDistFileFilterPath());
   53     QRegExp rx("(\\S+)\\s?\\(\\*\\.([\\w\\d]+)");
   54 
   55     if (filterDef.open(QIODevice::ReadOnly | QIODevice::Text)) {
   56         QTextStream in(&filterDef);
   57         QString line;
   58 
   59         QStringList syntaxPair;
   60         while (!in.atEnd()) {
   61             line = in.readLine();
   62             fileOpenFilter+=line;
   63             fileOpenFilter+=";;";
   64             if( rx.indexIn(line)!=-1) {
   65                 syntaxPair = rx.capturedTexts();
   66                 ui->comboSelectSyntax->addItem(syntaxPair[1], syntaxPair[2]);
   67             }
   68         }
   69     } else {
   70         fileOpenFilter="All files (*)";
   71     }
   72 
   73     // fill themes combo
   74 
   75 #ifdef Q_OS_OSX
   76     QDir themesDirClassic(QCoreApplication::applicationDirPath() + "/../Resources/themes");
   77     QDir themesDirBase16(QCoreApplication::applicationDirPath() + "/../Resources/themes/base16");
   78 
   79 #else
   80     #ifdef DATA_DIR
   81     QDir themesDirClassic(QString(DATA_DIR) + "/themes");
   82     QDir themesDirBase16(QString(DATA_DIR) + "/themes/base16");
   83     #else
   84     QDir themesDirClassic(QDir::currentPath()+"/themes");
   85     QDir themesDirBase16(QDir::currentPath()+"/themes/base16");
   86     #endif
   87 #endif
   88 
   89     QStringList filesClassic = themesDirClassic.entryList(QStringList("*.theme"), QDir::Files, QDir::Name);
   90     QStringList filesBase16 = themesDirBase16.entryList(QStringList("*.theme"), QDir::Files, QDir::Name);
   91 
   92     Diluculum::LuaState ls;
   93     Diluculum::LuaValueMap categoryMap;
   94 
   95     try {
   96         for (QStringList::const_iterator constIterator = filesClassic.constBegin();
   97                 constIterator != filesClassic.constEnd(); ++constIterator) {
   98             QString tPath(*constIterator);
   99             QString tCat;
  100 
  101             ls.doFile (themesDirClassic.absoluteFilePath(tPath).toStdString());
  102             QString tDesc (QString::fromStdString(ls["Description"].value().asString()));
  103             if (ls["Categories"].value() !=Diluculum::Nil){
  104 
  105                 categoryMap = ls["Categories"].value().asTable();
  106 
  107                 for(Diluculum::LuaValueMap::const_iterator it = categoryMap.begin(); it != categoryMap.end(); ++it)
  108                 {
  109                     tCat.append( QString::fromStdString( it->second.asString()));
  110                     tCat.append(",");
  111                 }
  112             }
  113             QList<QString> themeEntry = {tPath.section('.',0, 0), tDesc, tCat, "0"};
  114             themesList.append(themeEntry);
  115         }
  116 
  117         for (QStringList::const_iterator constIterator = filesBase16.constBegin();
  118                 constIterator != filesBase16.constEnd(); ++constIterator) {
  119             QString tPath(*constIterator);
  120             QString tCat;
  121 
  122             ls.doFile (themesDirBase16.absoluteFilePath(tPath).toStdString());
  123             QString tDesc (QString::fromStdString(ls["Description"].value().asString()));
  124             if (ls["Categories"].value() !=Diluculum::Nil){
  125 
  126                 categoryMap = ls["Categories"].value().asTable();
  127 
  128                 for(Diluculum::LuaValueMap::const_iterator it = categoryMap.begin(); it != categoryMap.end(); ++it)
  129                 {
  130                     tCat.append( QString::fromStdString( it->second.asString()));
  131                     tCat.append(",");
  132                 }
  133             }
  134             QList<QString> themeEntry = { tPath.section('.',0, 0), tDesc, tCat, "1"};
  135             themesList.append(themeEntry);
  136         }
  137     }  catch (Diluculum::LuaError &err) {
  138         QMessageBox::warning(this, tr("Initialization error"),
  139                              tr("Could not read a colour theme: ") + QString::fromStdString(err.what()));
  140     }
  141     ui->comboTheme->setCurrentIndex(0);
  142 
  143     ui->comboThemeFilter->addItem(tr("light"), "light");
  144     ui->comboThemeFilter->addItem(tr("dark"), "dark");
  145     ui->comboThemeFilter->addItem(tr("B16 light"), "light");
  146     ui->comboThemeFilter->addItem(tr("B16 dark"), "dark");
  147     ui->comboThemeFilter->setCurrentIndex(0);
  148 
  149     //does not work in GUI editor when adding > 10 items ?!?
  150     QStringList fmts;
  151     fmts << "Allman" << "GNU" <<"Google"<< "Horstmann"<<"Lisp"<<"Java"<<"K&R"<<"Linux"
  152          <<"Mozilla"<<"OTBS"<<"Pico"<<"Ratliff"<<"Stroustrup"<<"VTK"<<"Webkit"<<"Whitesmith";
  153     ui->comboReformat->clear();
  154     ui->comboReformat->addItems(fmts);
  155 
  156     // load syntax mappings
  157     if (!loadFileTypeConfig()) {
  158         QMessageBox::warning(this, tr("Initialization error"),
  159                              tr("Could not find syntax definitions. Check installation."));
  160     }
  161 
  162     //avoid ugly buttons in MacOS
  163     #ifndef Q_OS_OSX
  164     ui->pbPluginReadFilePath->setMaximumWidth(30);
  165     ui->pbOutputDest->setMaximumWidth(30);
  166     ui->pbHTMLChooseStyleIncFile->setMaximumWidth(30);
  167     ui->pbLATEXChooseStyleIncFile->setMaximumWidth(30);
  168     ui->pbTEXChooseStyleIncFile->setMaximumWidth(30);
  169     ui->pbSVGChooseStyleIncFile->setMaximumWidth(30);
  170     ui->tabIOSelection->setDocumentMode(false);
  171     #endif
  172 
  173     #ifdef Q_OS_WIN
  174     // https://forum.qt.io/topic/101391/windows-10-dark-theme/
  175     if (QSysInfo::productVersion()=="10") {
  176         QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",QSettings::NativeFormat);
  177         if(settings.value("AppsUseLightTheme")==0){
  178             qApp->setStyle(QStyleFactory::create("Fusion"));
  179             QPalette darkPalette;
  180             QColor darkColor = QColor(45,45,45);
  181             QColor disabledColor = QColor(127,127,127);
  182             darkPalette.setColor(QPalette::Window, darkColor);
  183             darkPalette.setColor(QPalette::WindowText, Qt::white);
  184             darkPalette.setColor(QPalette::Base, QColor(18,18,18));
  185             darkPalette.setColor(QPalette::AlternateBase, darkColor);
  186             darkPalette.setColor(QPalette::ToolTipBase, Qt::white);
  187             darkPalette.setColor(QPalette::ToolTipText, Qt::white);
  188             darkPalette.setColor(QPalette::Text, Qt::white);
  189             darkPalette.setColor(QPalette::Disabled, QPalette::Text, disabledColor);
  190             darkPalette.setColor(QPalette::Button, darkColor);
  191             darkPalette.setColor(QPalette::ButtonText, Qt::white);
  192             darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, disabledColor);
  193             darkPalette.setColor(QPalette::BrightText, Qt::red);
  194             darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
  195 
  196             darkPalette.setColor(QPalette::Highlight, QColor(153, 153, 153));
  197             darkPalette.setColor(QPalette::HighlightedText, Qt::black);
  198             darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, disabledColor);
  199 
  200             qApp->setPalette(darkPalette);
  201             qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #404040; border: 1px solid white; }");
  202         }
  203     }
  204     #endif
  205 
  206     QObject::connect(ui->pbOpenFiles, SIGNAL(clicked()), this, SLOT(openFiles()));
  207     QObject::connect(ui->action_Open_files, SIGNAL(triggered()), this, SLOT(openFiles()));
  208 
  209     QObject::connect(ui->cbWrite2Src, SIGNAL(clicked()), this, SLOT(plausibility()));
  210     QObject::connect(ui->cbIncLineNo, SIGNAL(clicked()), this, SLOT(plausibility()));
  211     QObject::connect(ui->cbWrapping, SIGNAL(clicked()), this, SLOT(plausibility()));
  212     QObject::connect(ui->cbEncoding, SIGNAL(clicked()), this, SLOT(plausibility()));
  213 
  214     QObject::connect(ui->comboFormat, SIGNAL(currentIndexChanged(int)), this, SLOT(plausibility()));
  215     QObject::connect(ui->cbReformat, SIGNAL(clicked()), this, SLOT(plausibility()));
  216     QObject::connect(ui->cbKwCase, SIGNAL(clicked()), this, SLOT(plausibility()));
  217     QObject::connect(ui->cbHTMLEmbedStyle, SIGNAL(clicked()), this, SLOT(plausibility()));
  218     QObject::connect(ui->cbHTMLAnchors, SIGNAL(clicked()), this, SLOT(plausibility()));
  219     QObject::connect(ui->cbHTMLInlineCSS, SIGNAL(clicked()), this, SLOT(plausibility()));
  220     QObject::connect(ui->cbLATEXEmbedStyle, SIGNAL(clicked()), this, SLOT(plausibility()));
  221     QObject::connect(ui->cbTEXEmbedStyle, SIGNAL(clicked()), this, SLOT(plausibility()));
  222     QObject::connect(ui->cbSVGEmbedStyle, SIGNAL(clicked()), this, SLOT(plausibility()));
  223     QObject::connect(ui->cbFragment, SIGNAL(clicked()), this, SLOT(plausibility()));
  224     QObject::connect(ui->tabIOSelection, SIGNAL(currentChanged(int)), this, SLOT(plausibility()));
  225 
  226     QObject::connect(ui->lvInputFiles, SIGNAL(itemSelectionChanged()), this, SLOT(updatePreview()));
  227     QObject::connect(ui->lvPluginScripts, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(updatePreview()));
  228     QObject::connect(ui->lvUserScripts, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(updatePreview()));
  229     QObject::connect(ui->lvUserScripts, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(plausibility()));
  230 
  231     QObject::connect(ui->cbIncLineNo, SIGNAL(clicked()), this, SLOT(updatePreview()));
  232     QObject::connect(ui->cbKwCase, SIGNAL(clicked()), this, SLOT(updatePreview()));
  233     QObject::connect(ui->cbPadZeroes, SIGNAL(clicked()), this, SLOT(updatePreview()));
  234     QObject::connect(ui->cbReformat, SIGNAL(clicked()), this, SLOT(updatePreview()));
  235     QObject::connect(ui->cbWrapping, SIGNAL(clicked()), this, SLOT(updatePreview()));
  236     QObject::connect(ui->cbAdvWrapping, SIGNAL(clicked()), this, SLOT(updatePreview()));
  237     QObject::connect(ui->cbValidateInput, SIGNAL(clicked()), this, SLOT(updatePreview()));
  238     QObject::connect(ui->cbEncoding, SIGNAL(clicked()), this, SLOT(updatePreview()));
  239     QObject::connect(ui->comboEncoding, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePreview()));
  240 
  241     QObject::connect(ui->comboFontName, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePreview()));
  242     QObject::connect(ui->comboKwCase, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePreview()));
  243     QObject::connect(ui->comboReformat, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePreview()));
  244     QObject::connect(ui->comboTheme, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePreview()));
  245     QObject::connect(ui->comboSelectSyntax, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePreview()));
  246     QObject::connect(ui->comboThemeFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePreview()));
  247 
  248     QObject::connect(ui->sbLineNoWidth, SIGNAL(valueChanged(int)), this, SLOT(updatePreview()));
  249     QObject::connect(ui->sbLineNoStart, SIGNAL(valueChanged(int)), this, SLOT(updatePreview()));
  250     QObject::connect(ui->leFontSize, SIGNAL(textChanged(QString)), this, SLOT(updatePreview()));
  251     QObject::connect(ui->cbOmitWrappedLineNumbers, SIGNAL(clicked()), this, SLOT(updatePreview()));
  252 
  253     QObject::connect(&scriptWatcher, SIGNAL(fileChanged(QString)), this, SLOT(updatePreview()));
  254 
  255     copyShortcut = new QShortcut(QKeySequence(QKeySequence::Copy), this);
  256     pasteShortcut = new QShortcut(QKeySequence(QKeySequence::Paste), this);
  257 
  258     QObject::connect(copyShortcut, SIGNAL(activated()), ui->pbCopyToCP, SLOT(click()));
  259     QObject::connect(pasteShortcut, SIGNAL(activated()), ui->pbPasteFromCB, SLOT(click()));
  260 
  261     ui->pbCopyToCP->setText(ui->pbCopyToCP->text().arg(QKeySequence(QKeySequence::Copy).toString(QKeySequence::NativeText)));
  262     ui->pbPasteFromCB->setText(ui->pbPasteFromCB->text().arg(QKeySequence(QKeySequence::Paste).toString(QKeySequence::NativeText)));
  263 
  264     setAcceptDrops(true);
  265 
  266     readSettings();
  267 
  268     fillThemeCombo(oldThemeIndex);
  269 
  270     twoPassOutFile=QDir::tempPath() + "/highlight_twopass.lua";
  271 
  272     plausibility();
  273 
  274     if (runFirstTime && shortNamesDisabled()) {
  275         QMessageBox::warning(this, tr("NTFS Short Names"), tr("NTFS short names may be disabled on your volumes. Highlight can not read input with multibyte file names if no short name is available. This information will no longer bother you."));
  276     }
  277 
  278     statusBar()->showMessage(tr("Always at your service"), 2500);
  279 }
  280 
  281 bool MainWindow::shortNamesDisabled() {
  282 #ifdef Q_OS_WIN
  283     QSettings reg("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\FileSystem",
  284     QSettings::NativeFormat);
  285     int disableShortNames=reg.value("NtfsDisable8dot3NameCreation",0).toInt();
  286     return disableShortNames;
  287 #else
  288     return false;
  289 #endif
  290 }
  291 
  292 void MainWindow::fillThemeCombo(int restoreVal)
  293 {
  294     QString catFilter = ui->comboThemeFilter->currentData().toString();
  295     bool isBase16 = ui->comboThemeFilter->currentIndex() >1;
  296     //catFilter = catFilter.remove(0,2);
  297     //qDebug()<<"catFilter "<<catFilter <<isBase16;
  298 
  299     ui->comboTheme->clear();
  300 
  301     for (int i = 0; i < themesList.size(); ++i) {
  302         QList<QString> curTheme = themesList.at(i);
  303         if ( (!isBase16 && curTheme.at(2).contains( catFilter) && !curTheme.at(2).contains( "base16")) ||
  304              (isBase16 && curTheme.at(2).contains( catFilter) && curTheme.at(2).contains( "base16")))
  305           ui->comboTheme->addItem(curTheme.at(1), curTheme.at(0));
  306     }
  307     ui->comboTheme->setCurrentIndex(restoreVal);
  308 
  309 }
  310 
  311 MainWindow::~MainWindow()
  312 {
  313     writeSettings();
  314     QFile::remove(twoPassOutFile);
  315 
  316     delete ui;
  317     delete copyShortcut;
  318     delete pasteShortcut;
  319 }
  320 
  321 void MainWindow::openFiles()
  322 {
  323     QStringList files = QFileDialog::getOpenFileNames(
  324                             this,
  325                             tr("Select one or more files to open"),
  326                             "",
  327                             fileOpenFilter);
  328 
  329     addToView(files, ui->lvInputFiles);
  330 }
  331 
  332 void MainWindow::selectSingleFile(QLineEdit* edit, const QString& title, const QString& filter)
  333 {
  334     QString fileName = QFileDialog::getOpenFileName(this, title, "", filter);
  335     if (!fileName.isEmpty()) edit->setText(fileName);
  336 }
  337 
  338 void MainWindow::addToView(const QStringList& list, QListWidget* listWidget, const QString& iconName, bool checkable, bool baseName)
  339 {
  340     QListWidgetItem *listItem;
  341     QString croppedName;
  342     for (QStringList::const_iterator constIterator = list.constBegin();
  343             constIterator != list.constEnd(); ++constIterator) {
  344 
  345         for (int i = 0; i < listWidget->count(); ++i) {
  346             if (listWidget->item(i)->data(Qt::UserRole).toString()==*constIterator)
  347                 return;
  348         }
  349 
  350         croppedName = baseName ? QFileInfo(*constIterator).baseName(): QFileInfo(*constIterator).fileName() ;
  351         if (croppedName.isEmpty()) break;
  352         listItem=new QListWidgetItem(QIcon(iconName), croppedName );
  353         listItem->setData(Qt::UserRole, *constIterator);
  354         listItem->setToolTip(*constIterator);
  355         if (checkable) listItem->setCheckState( Qt::Unchecked);
  356         listWidget->addItem(listItem );
  357     }
  358 }
  359 
  360 void MainWindow::on_pbOutputDest_clicked()
  361 {
  362     QFileDialog dialog(this, tr("Select destination directory"), "");
  363     dialog.setFileMode(QFileDialog::Directory);
  364     if (dialog.exec() && !dialog.selectedFiles().empty()) {
  365         ui->leOutputDest->setText(dialog.selectedFiles().at(0));
  366     }
  367 }
  368 
  369 void MainWindow::writeSettings()
  370 {
  371     QSettings settings(QSettings::IniFormat, QSettings::UserScope,
  372                        "andre-simon.de", "highlight-gui");
  373 
  374     settings.beginGroup("MainWindow");
  375     settings.setValue("geometry", saveGeometry());
  376     settings.setValue("windowState", saveState());
  377     settings.endGroup();
  378 
  379     settings.beginGroup("input");
  380     QStringList inFiles;
  381     for (int i=0; i<ui->lvInputFiles->count(); i++) {
  382         inFiles<<ui->lvInputFiles->item(i)->data(Qt::UserRole).toString();
  383     }
  384 
  385     QStringList plugins;
  386     for (int i=0; i<ui->lvPluginScripts->count(); i++) {
  387         plugins<<ui->lvPluginScripts->item(i)->data(Qt::UserRole).toString();
  388     }
  389 
  390     QVariantList selectedPlugins;
  391     for (int i=0; i<ui->lvPluginScripts->count(); i++) {
  392         if (ui->lvPluginScripts->item(i)->checkState()==Qt::Checked )
  393             selectedPlugins.push_back(QVariant(i));
  394     }
  395 
  396     QStringList userScripts;
  397     for (int i=0; i<ui->lvUserScripts->count(); i++) {
  398         userScripts<<ui->lvUserScripts->item(i)->data(Qt::UserRole).toString();
  399     }
  400 
  401     QVariantList selectedUserScripts;
  402     for (int i=0; i<ui->lvUserScripts->count(); i++) {
  403         if (ui->lvUserScripts->item(i)->checkState()==Qt::Checked )
  404             selectedUserScripts.push_back(QVariant(i));
  405     }
  406 
  407     const char* name="objectName";
  408     settings.setValue(ui->lvInputFiles->property(name).toString(),
  409                       inFiles);
  410     settings.setValue(ui->lvPluginScripts->property(name).toString(),
  411                       plugins);
  412     settings.setValue("selectedPlugins", selectedPlugins);
  413     settings.setValue(ui->lvUserScripts->property(name).toString(),
  414                       userScripts);
  415     settings.setValue("selectedUserScripts", selectedUserScripts);
  416 
  417     settings.setValue(ui->leOutputDest->property(name).toString(),
  418                       ui->leOutputDest->text());
  419     settings.setValue(ui->cbWrite2Src->property(name).toString(),
  420                       ui->cbWrite2Src->isChecked());
  421     settings.setValue(ui->cbAdvWrapping->property(name).toString(),
  422                       ui->cbAdvWrapping->isChecked());
  423     settings.setValue(ui->cbEncoding->property(name).toString(),
  424                       ui->cbEncoding->isChecked());
  425     settings.setValue(ui->cbFragment->property(name).toString(),
  426                       ui->cbFragment->isChecked());
  427     settings.setValue(ui->cbKeepInjections->property(name).toString(),
  428                       ui->cbKeepInjections->isChecked());
  429     settings.setValue(ui->cbHTMLAnchors->property(name).toString(),
  430                       ui->cbHTMLAnchors->isChecked());
  431     settings.setValue(ui->cbOmitVersionInfo->property(name).toString(),
  432                       ui->cbOmitVersionInfo->isChecked());
  433 
  434     settings.setValue(ui->cbHTMLEmbedStyle->property(name).toString(),
  435                       ui->cbHTMLEmbedStyle->isChecked());
  436     settings.setValue(ui->cbHTMLEnclosePreTags->property(name).toString(),
  437                       ui->cbHTMLEnclosePreTags->isChecked());
  438     settings.setValue(ui->cbHTMLFileNameAnchor->property(name).toString(),
  439                       ui->cbHTMLFileNameAnchor->isChecked());
  440     settings.setValue(ui->cbHTMLIndex->property(name).toString(),
  441                       ui->cbHTMLIndex->isChecked());
  442     settings.setValue(ui->cbHTMLInlineCSS->property(name).toString(),
  443                       ui->cbHTMLInlineCSS->isChecked());
  444     settings.setValue(ui->cbHTMLOrderedList->property(name).toString(),
  445                       ui->cbHTMLOrderedList->isChecked());
  446     settings.setValue(ui->cbIncLineNo->property(name).toString(),
  447                       ui->cbIncLineNo->isChecked());
  448     settings.setValue(ui->cbKwCase->property(name).toString(),
  449                       ui->cbKwCase->isChecked());
  450     settings.setValue(ui->cbLATEXBabel->property(name).toString(),
  451                       ui->cbLATEXBabel->isChecked());
  452     settings.setValue(ui->cbLATEXBeamer->property(name).toString(),
  453                       ui->cbLATEXBeamer->isChecked());
  454     settings.setValue(ui->cbLATEXEscQuotes->property(name).toString(),
  455                       ui->cbLATEXEscQuotes->isChecked());
  456     settings.setValue(ui->cbLATEXPrettySymbols->property(name).toString(),
  457                       ui->cbLATEXPrettySymbols->isChecked());
  458     settings.setValue(ui->cbPadZeroes->property(name).toString(),
  459                       ui->cbPadZeroes->isChecked());
  460     settings.setValue(ui->cbReformat->property(name).toString(),
  461                       ui->cbReformat->isChecked());
  462     settings.setValue(ui->cbRTFCharStyles->property(name).toString(),
  463                       ui->cbRTFCharStyles->isChecked());
  464     settings.setValue(ui->cbRTFPageColor->property(name).toString(),
  465                       ui->cbRTFPageColor->isChecked());
  466     settings.setValue(ui->cbWrapping->property(name).toString(),
  467                       ui->cbWrapping->isChecked());
  468     settings.setValue(ui->cbValidateInput->property(name).toString(),
  469                       ui->cbValidateInput->isChecked());
  470 
  471     settings.setValue(ui->comboFormat->property(name).toString(),
  472                       ui->comboFormat->currentIndex());
  473     settings.setValue(ui->comboKwCase->property(name).toString(),
  474                       ui->comboKwCase->currentIndex());
  475     settings.setValue(ui->comboReformat->property(name).toString(),
  476                       ui->comboReformat->currentIndex());
  477     settings.setValue(ui->comboRTFPageSize->property(name).toString(),
  478                       ui->comboRTFPageSize->currentIndex());
  479 
  480     settings.setValue(ui->comboTheme->property(name).toString(),
  481                       ui->comboTheme->currentIndex());
  482     settings.setValue(ui->comboThemeFilter->property(name).toString(),
  483                       ui->comboThemeFilter->currentIndex());
  484 
  485     settings.setValue(ui->comboEncoding->property(name).toString(),
  486                       ui->comboEncoding->currentText());
  487     settings.setValue(ui->comboFontName->property(name).toString(),
  488                       ui->comboFontName->currentText());
  489     settings.setValue(ui->comboSelectSyntax->property(name).toString(),
  490                       ui->comboSelectSyntax->currentIndex());
  491 
  492     settings.setValue(ui->leHTMLStyleFile->property(name).toString(),
  493                       ui->leHTMLStyleFile->text());
  494     settings.setValue(ui->leHTMLStyleIncFile->property(name).toString(),
  495                       ui->leHTMLStyleIncFile->text());
  496     settings.setValue(ui->leLATEXStyleFile->property(name).toString(),
  497                       ui->leLATEXStyleFile->text());
  498     settings.setValue(ui->leLATEXStyleIncFile->property(name).toString(),
  499                       ui->leLATEXStyleIncFile->text());
  500     settings.setValue(ui->leTEXStyleFile->property(name).toString(),
  501                       ui->leTEXStyleFile->text());
  502     settings.setValue(ui->leTEXStyleIncFile->property(name).toString(),
  503                       ui->leTEXStyleIncFile->text());
  504     settings.setValue(ui->leSVGStyleFile->property(name).toString(),
  505                       ui->leSVGStyleFile->text());
  506     settings.setValue(ui->leSVGStyleIncFile->property(name).toString(),
  507                       ui->leSVGStyleIncFile->text());
  508     settings.setValue(ui->lePluginReadFilePath->property(name).toString(),
  509                       ui->lePluginReadFilePath->text());
  510 
  511     settings.setValue(ui->cbSVGEmbedStyle->property(name).toString(),
  512                       ui->cbSVGEmbedStyle->isChecked());
  513     settings.setValue(ui->cbLATEXEmbedStyle->property(name).toString(),
  514                       ui->cbLATEXEmbedStyle->isChecked());
  515     settings.setValue(ui->cbTEXEmbedStyle->property(name).toString(),
  516                       ui->cbTEXEmbedStyle->isChecked());
  517     settings.setValue(ui->cbHTMLPasteMIME->property(name).toString(),
  518                       ui->cbHTMLPasteMIME->isChecked());
  519 
  520     settings.setValue(ui->leSVGHeight->property(name).toString(),
  521                       ui->leSVGHeight->text());
  522     settings.setValue(ui->leSVGWidth->property(name).toString(),
  523                       ui->leSVGWidth->text());
  524     settings.setValue(ui->leFontSize->property(name).toString(),
  525                       ui->leFontSize->text());
  526     settings.setValue(ui->sbLineLength->property(name).toString(),
  527                       ui->sbLineLength->value());
  528     settings.setValue(ui->sbTabWidth->property(name).toString(),
  529                       ui->sbTabWidth->value());
  530     settings.setValue(ui->tabWidget->property(name).toString(),
  531                       ui->tabWidget->currentIndex());
  532     settings.setValue(ui->leHTMLCssPrefix->property(name).toString(),
  533                       ui->leHTMLCssPrefix->text());
  534     settings.setValue(ui->tabIOSelection->property(name).toString(),
  535                       ui->tabIOSelection->currentIndex());
  536     settings.setValue(ui->sbLineNoWidth->property(name).toString(),
  537                       ui->sbLineNoWidth->value());
  538     settings.setValue(ui->sbLineNoStart->property(name).toString(),
  539                       ui->sbLineNoStart->value());
  540     settings.setValue(ui->tabWidgetOptions->property(name).toString(),
  541                       ui->tabWidgetOptions->currentIndex());
  542 
  543     settings.setValue("runFirstTime", false);
  544 
  545     settings.endGroup();
  546 }
  547 
  548 void MainWindow::readSettings()
  549 {
  550     ui->tabIOSelection->setCurrentIndex(0); // wie default setzen?
  551     QSettings settings(QSettings::IniFormat, QSettings::UserScope,
  552                        "andre-simon.de", "highlight-gui");
  553 
  554    // QMessageBox::information(this, "path", settings.fileName());
  555     if (!QFile(settings.fileName()).exists()) return;
  556 
  557     settings.beginGroup("MainWindow");
  558 
  559     restoreGeometry(settings.value("geometry").toByteArray());
  560     restoreState(settings.value("windowState").toByteArray());
  561 
  562     settings.endGroup();
  563 
  564     settings.beginGroup("input");
  565     const char*  name="objectName";
  566 
  567     addToView(settings.value(ui->lvInputFiles->property(name).toString()).toStringList(), ui->lvInputFiles ) ;
  568     addToView(settings.value(ui->lvPluginScripts->property(name).toString()).toStringList(), ui->lvPluginScripts, ":/plugin.png", true, true ) ;
  569     addToView(settings.value(ui->lvUserScripts->property(name).toString()).toStringList(), ui->lvUserScripts, ":/script.png", true, false ) ;
  570 
  571     QVariantList selectedPlugins=settings.value("selectedPlugins").toList();
  572     for (int i=0; i<selectedPlugins.size(); i++) {
  573         ui->lvPluginScripts->item(selectedPlugins[i].toInt())->setCheckState(Qt::Checked);
  574     }
  575     QVariantList selectedUserScripts=settings.value("selectedUserScripts").toList();
  576     for (int i=0; i<selectedUserScripts.size(); i++) {
  577         ui->lvUserScripts->item(selectedUserScripts[i].toInt())->setCheckState(Qt::Checked);
  578         on_lvUserScripts_itemClicked(ui->lvUserScripts->item(selectedUserScripts[i].toInt()));
  579     }
  580     ui->leOutputDest->setText(settings.value(ui->leOutputDest->property(name).toString()).toString());
  581     ui->cbWrite2Src->setChecked(settings.value(ui->cbWrite2Src->property(name).toString()).toBool());
  582     ui->cbAdvWrapping->setChecked(settings.value(ui->cbAdvWrapping->property(name).toString()).toBool());
  583     ui->cbEncoding->setChecked(settings.value(ui->cbEncoding->property(name).toString()).toBool());
  584     ui->cbFragment->setChecked(settings.value(ui->cbFragment->property(name).toString()).toBool());
  585     ui->cbKeepInjections->setChecked(settings.value(ui->cbKeepInjections->property(name).toString()).toBool());
  586     ui->cbOmitVersionInfo->setChecked(settings.value(ui->cbOmitVersionInfo->property(name).toString()).toBool());
  587 
  588     ui->cbHTMLAnchors->setChecked(settings.value(ui->cbHTMLAnchors->property(name).toString()).toBool());
  589     ui->cbHTMLEmbedStyle->setChecked(settings.value(ui->cbHTMLEmbedStyle->property(name).toString()).toBool());
  590     ui->cbHTMLEnclosePreTags->setChecked(settings.value(ui->cbHTMLEnclosePreTags->property(name).toString()).toBool());
  591     ui->cbHTMLFileNameAnchor->setChecked(settings.value(ui->cbHTMLFileNameAnchor->property(name).toString()).toBool());
  592     ui->cbHTMLIndex->setChecked(settings.value(ui->cbHTMLIndex->property(name).toString()).toBool());
  593     ui->cbHTMLInlineCSS->setChecked(settings.value(ui->cbHTMLInlineCSS->property(name).toString()).toBool());
  594     ui->cbHTMLOrderedList->setChecked(settings.value(ui->cbHTMLOrderedList->property(name).toString()).toBool());
  595     ui->cbIncLineNo->setChecked(settings.value(ui->cbIncLineNo->property(name).toString()).toBool());
  596     ui->cbKwCase->setChecked(settings.value(ui->cbKwCase->property(name).toString()).toBool());
  597     ui->cbLATEXBabel->setChecked(settings.value(ui->cbLATEXBabel->property(name).toString()).toBool());
  598     ui->cbLATEXBeamer->setChecked(settings.value(ui->cbLATEXBeamer->property(name).toString()).toBool());
  599 
  600     ui->cbLATEXEscQuotes->setChecked(settings.value(ui->cbLATEXEscQuotes->property(name).toString()).toBool());
  601     ui->cbLATEXPrettySymbols->setChecked(settings.value(ui->cbLATEXPrettySymbols->property(name).toString()).toBool());
  602 
  603     ui->cbPadZeroes->setChecked(settings.value(ui->cbPadZeroes->property(name).toString()).toBool());
  604     ui->cbReformat->setChecked(settings.value(ui->cbReformat->property(name).toString()).toBool());
  605     ui->cbRTFCharStyles->setChecked(settings.value(ui->cbRTFCharStyles->property(name).toString()).toBool());
  606     ui->cbRTFPageColor->setChecked(settings.value(ui->cbRTFPageColor->property(name).toString()).toBool());
  607     ui->cbWrapping->setChecked(settings.value(ui->cbWrapping->property(name).toString()).toBool());
  608     ui->cbValidateInput->setChecked(settings.value(ui->cbValidateInput->property(name).toString()).toBool());
  609 
  610     ui->comboEncoding->insertItem(0, settings.value(ui->comboEncoding->property(name).toString()).toString());
  611     ui->comboEncoding->setCurrentIndex(0);
  612     ui->comboFontName->insertItem(0, settings.value(ui->comboFontName->property(name).toString()).toString());
  613     ui->comboFontName->setCurrentIndex(0);
  614     ui->comboFormat->setCurrentIndex(settings.value(ui->comboFormat->property(name).toString()).toInt());
  615     ui->comboKwCase->setCurrentIndex(settings.value(ui->comboKwCase->property(name).toString()).toInt());
  616     ui->comboReformat->setCurrentIndex(settings.value(ui->comboReformat->property(name).toString()).toInt());
  617     ui->comboRTFPageSize->setCurrentIndex(settings.value(ui->comboRTFPageSize->property(name).toString()).toInt());
  618     ui->comboSelectSyntax->setCurrentIndex(settings.value(ui->comboSelectSyntax->property(name).toString()).toInt());
  619 
  620     oldThemeIndex=settings.value(ui->comboTheme->property(name).toString()).toInt();
  621     ui->comboThemeFilter->setCurrentIndex(settings.value(ui->comboThemeFilter->property(name).toString()).toInt());
  622 
  623     ui->leHTMLStyleFile->setText(settings.value(ui->leHTMLStyleFile->property(name).toString()).toString());
  624     ui->leHTMLStyleIncFile->setText(settings.value(ui->leHTMLStyleIncFile->property(name).toString()).toString());
  625     ui->leLATEXStyleFile->setText(settings.value(ui->leLATEXStyleFile->property(name).toString()).toString());
  626     ui->leTEXStyleFile->setText(settings.value(ui->leTEXStyleFile->property(name).toString()).toString());
  627     ui->leLATEXStyleIncFile->setText(settings.value(ui->leLATEXStyleIncFile->property(name).toString()).toString());
  628     ui->leTEXStyleIncFile->setText(settings.value(ui->leTEXStyleIncFile->property(name).toString()).toString());
  629     ui->leSVGHeight->setText(settings.value(ui->leSVGHeight->property(name).toString()).toString());
  630     ui->leSVGWidth->setText(settings.value(ui->leSVGWidth->property(name).toString()).toString());
  631     ui->leFontSize->setText(settings.value(ui->leFontSize->property(name).toString()).toString());
  632     ui->leHTMLCssPrefix->setText(settings.value(ui->leHTMLCssPrefix->property(name).toString()).toString());
  633     ui->lePluginReadFilePath->setText(settings.value(ui->lePluginReadFilePath->property(name).toString()).toString());
  634 
  635     ui->sbLineLength->setValue(settings.value(ui->sbLineLength->property(name).toString()).toInt());
  636     ui->sbTabWidth->setValue(settings.value(ui->sbTabWidth->property(name).toString()).toInt());
  637     ui->cbTEXEmbedStyle->setChecked(settings.value(ui->cbTEXEmbedStyle->property(name).toString()).toBool());
  638     ui->cbLATEXEmbedStyle->setChecked(settings.value(ui->cbLATEXEmbedStyle->property(name).toString()).toBool());
  639     ui->cbSVGEmbedStyle->setChecked(settings.value(ui->cbSVGEmbedStyle->property(name).toString()).toBool());
  640     ui->cbHTMLPasteMIME->setChecked(settings.value(ui->cbHTMLPasteMIME->property(name).toString()).toBool());
  641 
  642     ui->tabWidget->setCurrentIndex(settings.value(ui->tabWidget->property(name).toString()).toInt());
  643     ui->tabIOSelection->setCurrentIndex(settings.value(ui->tabIOSelection->property(name).toString()).toInt());
  644     ui->tabWidgetOptions->setCurrentIndex(settings.value(ui->tabWidgetOptions->property(name).toString()).toInt());
  645 
  646     ui->sbLineNoWidth->setValue(settings.value(ui->sbLineNoWidth->property(name).toString(), 2).toInt());
  647     ui->sbLineNoStart->setValue(settings.value(ui->sbLineNoStart->property(name).toString(), 1).toInt());
  648 
  649     runFirstTime = settings.value("runFirstTime", true).toBool();
  650 
  651     settings.endGroup();
  652 }
  653 
  654 void MainWindow::readLuaList(const string& paramName, const string& langName,Diluculum::LuaValue &luaVal, MMap* extMap){
  655     int extIdx=1;
  656     string val;
  657     while (luaVal[paramName][extIdx] !=Diluculum::Nil) {
  658         val = luaVal[paramName][extIdx].asString();
  659         extMap->insert ( make_pair ( val,  langName ) );
  660         extIdx++;
  661     }
  662 }
  663 
  664 bool MainWindow::loadFileTypeConfig()
  665 {
  666     QString filetypesPath=getDistFileConfigPath();
  667 #ifdef Q_OS_WIN
  668    filetypesPath = getWindowsShortPath(filetypesPath);
  669 #endif
  670 
  671     try {
  672         Diluculum::LuaState ls;
  673         ls.doFile (filetypesPath.toStdString());
  674         int idx=1;
  675         string langName;
  676         Diluculum::LuaValue mapEntry;
  677         while ((mapEntry = ls["FileMapping"][idx].value()) !=Diluculum::Nil) {
  678             langName = mapEntry["Lang"].asString();
  679             if (mapEntry["Extensions"] !=Diluculum::Nil) {
  680                 readLuaList("Extensions", langName, mapEntry,  &assocByExtension);
  681             } else if (mapEntry["Filenames"] !=Diluculum::Nil) {
  682                 readLuaList("Filenames", langName, mapEntry,  &assocByFilename);
  683             } else if (mapEntry["Shebang"] !=Diluculum::Nil) {
  684                 assocByShebang.insert ( make_pair ( mapEntry["Shebang"].asString(),  langName ) );
  685             } else if (mapEntry["EncodingHint"] !=Diluculum::Nil) {
  686                 encodingHints.insert ( make_pair ( langName, mapEntry["EncodingHint"].asString() ) );
  687             }
  688             idx++;
  689         }
  690     } catch (Diluculum::LuaError &err) {
  691         QMessageBox::warning(this, "Configuration error", QString::fromStdString( err.what()));
  692         return false;
  693     }
  694     return true;
  695 }
  696 
  697 string MainWindow::analyzeFile(const string& file)
  698 {
  699     ifstream inFile(file.c_str());
  700     string firstLine;
  701     getline (inFile, firstLine);
  702     SMap::iterator it;
  703 
  704     boost::xpressive::sregex rex;
  705     boost::xpressive::smatch what;
  706     for ( it=assocByShebang.begin(); it!=assocByShebang.end(); it++ ) {
  707         rex = boost::xpressive::sregex::compile( it->first );
  708         if ( boost::xpressive::regex_search( firstLine, what, rex )  ) return it->second;
  709     }
  710     return "";
  711 }
  712 
  713 string MainWindow::getFileType(const string& suffix, const string &inputFile)
  714 {
  715     string baseName = getFileBaseName(inputFile);
  716     if (assocByFilename.count(baseName)) return assocByFilename.find(baseName)->second;
  717 
  718     string lcSuffix = StringTools::change_case(suffix);
  719     if (assocByExtension.count(lcSuffix)) {
  720 
  721         string langAssociation;
  722         MMap::iterator it = assocByExtension.find(lcSuffix);
  723         if (it!=assocByExtension.end()) langAssociation = it->second;
  724 
  725         std::pair <MMap::iterator, MMap::iterator> ret;
  726         ret = assocByExtension.equal_range(lcSuffix);
  727 
  728         std::list<std::string> lst;
  729         for (MMap::iterator it=ret.first; it!=ret.second; ++it){
  730            lst.push_back( it->second );
  731         }
  732 
  733         if (lst.size() > 1){
  734 
  735             if (rememberedAssoc.count(lcSuffix)) return rememberedAssoc[lcSuffix];
  736 
  737             syntax_chooser chooser;
  738             chooser.setUnclearExtension(QString(lcSuffix.c_str()));
  739              for (std::list<string>::iterator it=lst.begin(); it != lst.end(); ++it){
  740                  chooser.addSyntaxName(QString((*it).c_str()));
  741             }
  742             chooser.exec();
  743 
  744             string selectedLang = chooser.getSelection().toStdString();
  745 
  746             if (chooser.getRememberFlag()){
  747                 rememberedAssoc[lcSuffix]=selectedLang;
  748             }
  749             return selectedLang;
  750         }
  751         return langAssociation;
  752     }
  753 
  754     // Not configured in filetypes.conf, try shebang and finally the unmodified extension
  755     string shebang = analyzeFile(inputFile);
  756     if (!shebang.empty()) return shebang;
  757     return lcSuffix;
  758 }
  759 
  760 string MainWindow::getFileBaseName(const string& fileName){
  761     size_t psPos = fileName.rfind ( /*Platform::pathSeparator*/ '/' );
  762     return  (psPos==string::npos) ? fileName : fileName.substr(psPos+1, fileName.length());
  763 }
  764 
  765 string MainWindow::getFileSuffix(const string& fileName)
  766 {
  767     size_t ptPos=fileName.rfind(".");
  768     size_t psPos = fileName.rfind ( /*Platform::pathSeparator*/ '/' );
  769 
  770     if (ptPos == string::npos) {
  771         return  (psPos==string::npos) ? fileName : fileName.substr(psPos+1, fileName.length());
  772     }
  773     return (psPos!=string::npos && psPos>ptPos) ? fileName.substr(psPos+1, fileName.length()) : fileName.substr(ptPos+1, fileName.length());
  774 }
  775 
  776 void MainWindow::on_action_Exit_triggered()
  777 {
  778     this->close();
  779 }
  780 
  781 void MainWindow::on_action_About_Highlight_triggered()
  782 {
  783     QMessageBox::about( this, "About Highlight",
  784                         QString("Highlight is a code to formatted text converter.\n\n"
  785                                 "Highlight GUI %1\n"
  786                                 "(C) 2002-2020 Andre Simon <a.simon at mailbox.org>\n\n"
  787                                 "Artistic Style Classes\n(C) 1998-2002 Tal Davidson\n"
  788                                 "(C) 2006-2018 Jim Pattee <jimp03 at email.com>\n\n"
  789                                 "Diluculum Lua wrapper\n"
  790                                 "(C) 2005-2013 by Leandro Motta Barros\n\n"
  791                                 "Built with Qt version %2\n\n"
  792                                 "Released under the terms of the GNU GPL license.\n\n"
  793                                 "The highlight logo is based on the image \"Alcedo Atthis\" by Lukasz Lukasik.\n"
  794                                 "The original was published under the terms of the GNU FDL in the Wikimedia Commons database.\n\n"
  795                                ).arg(HIGHLIGHT_VERSION).arg(QString(qVersion ())) );
  796 }
  797 
  798 highlight::OutputType MainWindow::getOutputType()
  799 {
  800     switch (ui->comboFormat->currentIndex()) {
  801     case 0:
  802         return highlight::HTML;
  803     case 1:
  804         return highlight::XHTML;
  805     case 2:
  806         return highlight::LATEX;
  807     case 3:
  808         return highlight::TEX;
  809     case 4:
  810         return highlight::RTF;
  811     case 5:
  812         return highlight::ODTFLAT;
  813     case 6:
  814         return highlight::SVG;
  815     case 7:
  816         return highlight::BBCODE;
  817 
  818     case 8:
  819         return highlight::ESC_ANSI;
  820     case 9:
  821         return highlight::ESC_XTERM256;
  822     case 10:
  823         return highlight::ESC_TRUECOLOR;
  824 
  825     }
  826     return highlight::HTML;
  827 }
  828 
  829 QString MainWindow::getOutFileSuffix()
  830 {
  831     switch (ui->comboFormat->currentIndex()) {
  832     case 0:
  833         return ".html";
  834     case 1:
  835         return ".xhtml";
  836     case 2:
  837     case 3:
  838         return ".tex";
  839     case 4:
  840         return ".rtf";
  841     case 5:
  842         return ".fodt";
  843     case 6:
  844         return ".svg";
  845     case 7:
  846         return ".bbcode";
  847     case 8:
  848     case 9:
  849     case 10:
  850         return ".esc";
  851     }
  852     return ".html";
  853 }
  854 
  855 void MainWindow::applyCtrlValues(highlight::CodeGenerator* generator, bool previewMode)
  856 {
  857     if (!generator) return;
  858 
  859     highlight::OutputType outType=getOutputType();
  860 
  861     if (!previewMode) {
  862         QLineEdit * styleIncFile=NULL;
  863         QLineEdit * styleOutFile=NULL;
  864         QCheckBox * embedStyle=NULL;
  865 
  866         switch(outType) {
  867         case highlight::HTML:
  868         case highlight::XHTML:
  869             styleIncFile = ui->leHTMLStyleIncFile;
  870             styleOutFile = ui->leHTMLStyleFile;
  871             embedStyle  = ui->cbHTMLEmbedStyle;
  872             break;
  873         case highlight::LATEX:
  874             styleIncFile = ui->leLATEXStyleIncFile;
  875             styleOutFile = ui->leLATEXStyleFile;
  876             embedStyle  = ui->cbLATEXEmbedStyle;
  877             break;
  878         case highlight::TEX:
  879             styleIncFile = ui->leTEXStyleIncFile;
  880             styleOutFile = ui->leTEXStyleFile;
  881             embedStyle  = ui->cbTEXEmbedStyle;
  882             break;
  883         case highlight::SVG:
  884             styleIncFile = ui->leSVGStyleIncFile;
  885             styleOutFile = ui->leSVGStyleFile;
  886             embedStyle  = ui->cbSVGEmbedStyle;
  887             break;
  888         default:
  889             break;
  890         }
  891         if (styleIncFile)
  892             generator->setStyleInputPath(QDir::toNativeSeparators(styleIncFile->text()).toStdString());
  893         if (styleOutFile)
  894             generator->setStyleOutputPath(styleOutFile->text().toStdString());
  895         if (embedStyle)
  896             generator->setIncludeStyle(embedStyle->isChecked());
  897 
  898         generator->setFragmentCode(ui->cbFragment->isChecked());
  899         generator->setKeepInjections(ui->cbKeepInjections->isChecked());
  900 
  901         generator->setHTMLAttachAnchors(ui->cbHTMLAnchors->isChecked());
  902         generator->setHTMLOrderedList(ui->cbIncLineNo->isChecked() && ui->cbHTMLOrderedList->isChecked());
  903         generator->setHTMLInlineCSS(ui->cbHTMLInlineCSS->isChecked() && ui->cbHTMLInlineCSS->isEnabled());
  904         generator->setHTMLEnclosePreTag(ui->cbHTMLEnclosePreTags->isChecked());
  905 
  906         if (ui->leHTMLCssPrefix->text().size())
  907             generator->setHTMLClassName(ui->leHTMLCssPrefix->text().toStdString());
  908 
  909         generator->setLATEXReplaceQuotes(ui->cbLATEXEscQuotes->isChecked());
  910         generator->setLATEXNoShorthands(ui->cbLATEXBabel->isChecked());
  911         generator->setLATEXPrettySymbols(ui->cbLATEXPrettySymbols->isChecked());
  912         generator->setLATEXBeamerMode(ui->cbLATEXBeamer->isChecked());
  913 
  914         generator->setRTFPageSize(ui->comboRTFPageSize->currentText().toLower().toStdString());
  915         generator->setRTFCharStyles(ui->cbRTFCharStyles->isChecked());
  916         generator->setRTFPageColor(ui->cbRTFPageColor->isChecked());
  917 
  918         generator->setSVGSize(ui->leSVGWidth->text().toStdString(), ui->leSVGHeight->text().toStdString());
  919     }
  920 
  921     generator->setPrintLineNumbers( ui->cbIncLineNo->isChecked(), ui->sbLineNoStart->value());
  922     generator->setPrintZeroes(ui->cbPadZeroes->isEnabled() && ui->cbPadZeroes->isChecked());
  923     
  924     //TODO Check Windows MB Path
  925     generator->setPluginParameter(ui->lePluginReadFilePath->text().toStdString());
  926     generator->setOmitVersionComment(ui->cbHTMLPasteMIME->isChecked() || ui->cbOmitVersionInfo->isChecked());
  927     
  928     generator->setFilesCnt( previewMode ? 1 :  ui->lvInputFiles->count() );
  929 
  930     QString themePath=getUserScriptPath("theme");
  931 
  932     if (themePath.isEmpty()){
  933         themePath=getDistThemePath();
  934     }
  935 
  936 #ifdef Q_OS_WIN
  937         themePath = getWindowsShortPath(themePath);                
  938 #endif
  939 
  940 
  941     //TODO Check Windows MB Path
  942 
  943     for (int i=0; i<ui->lvPluginScripts->count(); i++) {
  944         if (ui->lvPluginScripts->item(i)->checkState()==Qt::Checked) {
  945             QString pluginPath=ui->lvPluginScripts->item(i)->data(Qt::UserRole).toString();
  946 #ifdef Q_OS_WIN
  947         pluginPath = getWindowsShortPath(pluginPath);
  948 #endif
  949             if (!generator->initPluginScript(pluginPath.toStdString()) ) {
  950                 QMessageBox::critical(this,"Plug-In init error", QString::fromStdString(generator->getPluginScriptError()));
  951             }
  952         }
  953     }
  954 
  955     if (!generator->initTheme(themePath.toStdString())) {
  956         QMessageBox::critical(this,"Theme init error", QString::fromStdString(generator->getThemeInitError()));
  957     }
  958 
  959    
  960     generator->setValidateInput(ui->cbValidateInput->isChecked());
  961     generator->setLineNumberWidth(ui->sbLineNoWidth->value());
  962     generator->setNumberWrappedLines(!ui->cbOmitWrappedLineNumbers->isChecked());
  963 
  964     if (getOutputType()!=highlight::LATEX && getOutputType()!=highlight::TEX) {
  965         string fntName=ui->comboFontName->currentText().toStdString();
  966         if(fntName.size()) generator->setBaseFont(fntName);
  967         string fntSize=ui->leFontSize->text().toStdString();
  968         if(fntSize.size()) generator->setBaseFontSize(fntSize);
  969     }
  970 
  971     int lineLength = 0;
  972     if (ui->cbWrapping->isChecked()) {
  973         lineLength = (   ui->cbIncLineNo->isChecked()
  974                          && ui->sbLineNoWidth->value() >  ui->sbLineLength->value())?
  975                      ui->sbLineLength->value() - ui->sbLineNoWidth->value()
  976                      :  ui->sbLineLength->value();
  977     }
  978     generator->setPreformatting(getWrappingStyle(), lineLength, ui->sbTabWidth->value());
  979 
  980     if(ui->cbKwCase->isChecked()) {
  981         StringTools::KeywordCase kwCase=StringTools::CASE_UNCHANGED;
  982         switch (ui->comboKwCase->currentIndex()) {
  983         case 0:
  984             kwCase=StringTools::CASE_UPPER;
  985             break;
  986         case 1:
  987             kwCase=StringTools::CASE_LOWER;
  988             break;
  989         case 2:
  990             kwCase=StringTools::CASE_CAPITALIZE;
  991             break;
  992         }
  993         generator->setKeyWordCase(kwCase);
  994     }
  995 
  996     if (ui->cbReformat->isChecked()) {
  997         generator->initIndentationScheme(ui->comboReformat->currentText().toLower().toStdString());
  998     }
  999 }
 1000 
 1001 highlight::WrapMode MainWindow::getWrappingStyle()
 1002 {
 1003     if (!ui->cbAdvWrapping->isChecked() && ui->cbAdvWrapping->isEnabled())
 1004         return highlight::WRAP_SIMPLE;
 1005     return (ui->cbWrapping->isChecked())?highlight::WRAP_DEFAULT:highlight::WRAP_DISABLED;
 1006 }
 1007 
 1008 void MainWindow::applyEncoding(highlight::CodeGenerator* generator, QString &langDefPath) {
 1009     if (ui->cbEncoding->isChecked()) {
 1010         generator->setEncoding(ui->comboEncoding->currentText().toStdString());
 1011     } else {
 1012 
 1013         string encoding="none";
 1014         //syntax definition setting:
 1015         string encodingHint= generator->getSyntaxEncodingHint();
 1016         if (encodingHint.size())
 1017             encoding=encodingHint;
 1018         
 1019         // filetypes.conf setting has higher priority:
 1020         encodingHint= encodingHints[QFileInfo(langDefPath).baseName().toStdString()];
 1021         if (encodingHint.size())
 1022             encoding=encodingHint;
 1023 
 1024         generator->setEncoding(encoding);
 1025     }
 1026 }
 1027 
 1028 void MainWindow::on_pbStartConversion_clicked()
 1029 {
 1030     if (!ui->lvInputFiles->count()) return;
 1031 
 1032     if (!ui->cbWrite2Src->isChecked() ) {
 1033 
 1034         if (ui->leOutputDest->text().isEmpty()){
 1035             ui->pbOutputDest->click();
 1036             return;
 1037         }
 1038         if (!QDir(ui->leOutputDest->text()).exists()){
 1039             QMessageBox::warning(this, tr("Output error"), tr("Output directory does not exist!"));
 1040             ui->leOutputDest->setFocus();
 1041             return;
 1042         }
 1043     }
 1044 
 1045     highlight::OutputType outType = getOutputType();
 1046     QCheckBox* cbEmbed=NULL;
 1047     QLineEdit* leStyleFile=NULL;
 1048 
 1049     if ( outType==highlight::HTML || outType==highlight::XHTML) {
 1050         cbEmbed = ui->cbHTMLEmbedStyle;
 1051         leStyleFile = ui->leHTMLStyleFile;
 1052     } else if ( outType==highlight::LATEX ) {
 1053         cbEmbed = ui->cbLATEXEmbedStyle;
 1054         leStyleFile = ui->leLATEXStyleFile;
 1055     } else if (outType==highlight::TEX ) {
 1056         cbEmbed = ui->cbTEXEmbedStyle;
 1057         leStyleFile = ui->leTEXStyleFile;
 1058     }    else if (outType==highlight::SVG ) {
 1059         cbEmbed = ui->cbSVGEmbedStyle;
 1060         leStyleFile = ui->leSVGStyleFile;
 1061     }
 1062 
 1063     if (cbEmbed && leStyleFile ) {
 1064         if ( !cbEmbed->isChecked() && leStyleFile->text().isEmpty()) {
 1065             ui->tabWidget->setCurrentIndex(1);
 1066             if ( outType==highlight::HTML || outType==highlight::XHTML) {
 1067                 ui->tabWidget->setCurrentIndex(0);
 1068             }
 1069             leStyleFile->setFocus();
 1070             QMessageBox::warning(this, tr("Output error"), tr("You must define a style output file!"));
 1071             return;
 1072         }
 1073     }
 1074     ui->pbStartConversion->setDisabled(true);
 1075     ui->pbCopyFile2CP->setDisabled(true);
 1076     this->setCursor(Qt::WaitCursor);
 1077 
 1078     QElapsedTimer t;
 1079     t.start();
 1080 
 1081     std::unique_ptr<highlight::CodeGenerator> generator(highlight::CodeGenerator::getInstance(outType));
 1082 
 1083     applyCtrlValues(generator.get(), false);
 1084     string currentFile;
 1085     string outfileName;
 1086     highlight::ParseError error;
 1087     highlight::LoadResult loadRes;
 1088     bool twoPassMode=false;
 1089 
 1090     QString langDefPath;
 1091     QString userLangPath = getUserScriptPath("lang");
 1092 
 1093     QString inFileName, inFilePath, origFilePath;
 1094     QString lastStyleDestDir;
 1095     QSet<QString> usedFileNames;
 1096 
 1097     QStringList inputErrors, outputErrors, reformatErrors, syntaxTestErrors;
 1098 
 1099     int i=-1;
 1100     while ( ++i<ui->lvInputFiles->count()) {
 1101 
 1102         if (i==0 && twoPassMode) {
 1103 
 1104              if ( !generator->initPluginScript(twoPassOutFile.toStdString()) ) {
 1105                  QMessageBox::critical(this,"Plug-In init error", QString::fromStdString(generator->getPluginScriptError()));
 1106                  break;
 1107             }
 1108         }
 1109 
 1110         inFilePath = origFilePath =  ui->lvInputFiles->item(i)->data(Qt::UserRole).toString();
 1111 
 1112 #ifdef Q_OS_WIN
 1113 
 1114         inFilePath = getWindowsShortPath(inFilePath);
 1115 
 1116 #endif
 1117         currentFile = inFilePath.toStdString();
 1118 
 1119         statusBar()->showMessage(tr("Processing %1 (%2/%3)").arg(origFilePath).arg(i+1).arg(ui->lvInputFiles->count()));
 1120 
 1121         langDefPath = (userLangPath.isEmpty()) ? getDistLangPath(getFileType(getFileSuffix(currentFile), currentFile)) : userLangPath;
 1122 
 1123 #ifdef Q_OS_WIN
 1124         langDefPath = getWindowsShortPath(langDefPath);                
 1125 #endif
 1126 
 1127         loadRes=generator->loadLanguage(langDefPath.toStdString());
 1128         if (loadRes==highlight::LOAD_FAILED_REGEX) {
 1129             QMessageBox::warning(this, tr("Language definition error"),
 1130                                  tr("Invalid regular expression in %1:\n%2").arg(langDefPath).arg(
 1131                                      QString::fromStdString( generator->getSyntaxRegexError())));
 1132             break;
 1133         } else  if (loadRes==highlight::LOAD_FAILED) {
 1134             QMessageBox::warning(this, tr("Unknown syntax"), tr("Could not convert %1").arg(origFilePath));
 1135             inputErrors.append(origFilePath);
 1136         } else  if (loadRes==highlight::LOAD_FAILED_LUA) {
 1137             QMessageBox::warning(this, tr("Lua error"), tr("Could not convert %1:\nLua Syntax error: %2").arg(origFilePath).arg(QString::fromStdString(generator->getSyntaxLuaError())) );
 1138             inputErrors.append(origFilePath);
 1139         } else {
 1140 
 1141             if (twoPassMode && !generator->syntaxRequiresTwoPassRun()) {
 1142                  continue;
 1143             }
 1144 
 1145             if (ui->cbReformat->isChecked()&& !generator->formattingIsPossible()) {
 1146                 reformatErrors.append(inFilePath);
 1147             }
 1148 
 1149             inFileName = ui->lvInputFiles->item(i)->text();
 1150             if (ui->cbWrite2Src->isChecked()) {
 1151 
 1152                 QString absOutPath=origFilePath + getOutFileSuffix();
 1153 
 1154 #ifdef Q_OS_WIN
 1155                 QFile file( absOutPath );
 1156                 if ( file.open(QIODevice::ReadWrite) )
 1157                 {
 1158                     absOutPath = getWindowsShortPath(absOutPath);
 1159                 }
 1160 #endif
 1161                 outfileName = absOutPath.toStdString();
 1162             } else {
 1163                 QFileInfo outFileInfo;
 1164                 QString fName=inFileName;
 1165                 if (usedFileNames.contains(fName)) {
 1166 
 1167                     QString prefix=QFileInfo(inFilePath).canonicalPath()+ QDir::separator();
 1168 #ifdef Q_OS_WIN
 1169                     prefix.remove(0,2); // Get rid of drive letter and ':'
 1170 #endif
 1171                     prefix.replace('/', '_');
 1172                     prefix.replace('\\', '_');
 1173                     fName.insert(0, prefix);
 1174 
 1175                 } else {
 1176                     usedFileNames.insert(fName);
 1177                 }
 1178                 outFileInfo.setFile(ui->leOutputDest->text(),fName);
 1179 
 1180                 QString absOutPath=outFileInfo.absoluteFilePath() + getOutFileSuffix();
 1181 
 1182 #ifdef Q_OS_WIN
 1183                 QFile file( absOutPath );
 1184                 if ( file.open(QIODevice::ReadWrite) )
 1185                 {
 1186                     absOutPath = getWindowsShortPath(absOutPath);
 1187                 }
 1188 #endif
 1189                 outfileName = absOutPath.toStdString();
 1190             }
 1191 
 1192             if (ui->cbHTMLFileNameAnchor->isChecked()) {
 1193                 generator->setHTMLAnchorPrefix(inFileName.toStdString());
 1194             }
 1195             generator->setTitle(inFileName.toStdString());
 1196       
 1197             applyEncoding(generator.get(), langDefPath);
 1198             
 1199             error = generator->generateFile(currentFile, outfileName );
 1200             if (error != highlight::PARSE_OK) {
 1201                 if (error == highlight::BAD_INPUT) {
 1202                     inputErrors.append(origFilePath);
 1203                 } else {
 1204                     outputErrors.append(origFilePath);
 1205                 }
 1206             }
 1207             ui->progressBar->setValue(100*i / ui->lvInputFiles->count());
 1208         }
 1209 
 1210         if (i==ui->lvInputFiles->count()-1 && generator->requiresTwoPassParsing() && twoPassOutFile.size()
 1211                     && inputErrors.size()==0 && outputErrors.size()==0 && !twoPassMode) {
 1212                 //QMessageBox::information(this, "print3", "print 3");
 1213 
 1214                 bool success=generator->printPersistentState(twoPassOutFile.toStdString());
 1215                 if ( !success ) {
 1216                     outputErrors.append(twoPassOutFile);
 1217                 } else {
 1218                     twoPassMode=true;
 1219 
 1220                     //start over, add plug-in to list in next iteration
 1221                     usedFileNames.clear();
 1222                     generator->resetSyntaxReaders();
 1223                     i=-1;
 1224                     ui->progressBar->setValue(0);
 1225                 }
 1226          }
 1227     }
 1228 
 1229     generator->clearPersistentSnippets();
 1230 
 1231     // write external Stylesheet
 1232     if ( cbEmbed && leStyleFile && !cbEmbed->isChecked()) {
 1233 
 1234         QString styleDestDir(ui->cbWrite2Src->isChecked() ? QFileInfo(inFilePath).path() : ui->leOutputDest->text() );
 1235 
 1236         if (lastStyleDestDir!=styleDestDir){
 1237             lastStyleDestDir = styleDestDir;
 1238             QString stylePath=QFileInfo(styleDestDir, leStyleFile->text()).absoluteFilePath();
 1239 
 1240 #ifdef Q_OS_WIN
 1241             QFile file( stylePath );
 1242             if ( file.open(QIODevice::ReadWrite) )
 1243             {
 1244                 stylePath = getWindowsShortPath(stylePath);
 1245             }
 1246 #endif
 1247             bool styleFileOK=generator -> printExternalStyle(QDir::toNativeSeparators(stylePath).toStdString());
 1248             if (!styleFileOK) {
 1249                 outputErrors.append(stylePath);
 1250             }
 1251         }
 1252     }
 1253 
 1254     // write HTML index file
 1255     if (    (outType==highlight::HTML || outType==highlight::XHTML)
 1256             && ui->cbHTMLIndex->isChecked() && !ui->cbWrite2Src->isChecked()) {
 1257         vector <string>  fileList;
 1258         for (int i=0; i<ui->lvInputFiles->count(); i++) {
 1259             fileList.push_back(QDir::toNativeSeparators(ui->lvInputFiles->item(i)->data(Qt::UserRole).toString()).toStdString());
 1260         }
 1261         QString outPath = QDir::toNativeSeparators(ui->leOutputDest->text());
 1262         if (!outPath.endsWith(QDir::separator())) outPath.append(QDir::separator());
 1263         outPath.append("index");
 1264         outPath.append(getOutFileSuffix());
 1265 #ifdef Q_OS_WIN
 1266                 QFile file( outPath );
 1267                 if ( file.open(QIODevice::ReadWrite) )
 1268                 {
 1269                     outPath = getWindowsShortPath(outPath);
 1270                 }
 1271 #endif
 1272 
 1273         bool indexFileOK=generator->printIndexFile(fileList, outPath.toStdString());
 1274         if (!indexFileOK) {
 1275             outputErrors.append(outPath);
 1276         }
 1277     }
 1278 
 1279     vector<string> posTestErrors = generator->getPosTestErrors();
 1280     for (vector<string>::iterator it=posTestErrors.begin(); it!=posTestErrors.end(); it++ ) {
 1281            syntaxTestErrors.append(QString::fromStdString(*it));
 1282     }
 1283 
 1284     statusBar()->showMessage(tr("Converted %1 files in %2 ms").arg(ui->lvInputFiles->count()).arg(t.elapsed()));
 1285     ui->progressBar->reset();
 1286     this->setCursor(Qt::ArrowCursor);
 1287     ui->pbStartConversion->setEnabled(true);
 1288     ui->pbCopyFile2CP->setEnabled(true);
 1289 
 1290     if (!inputErrors.isEmpty() || !outputErrors.isEmpty() || !reformatErrors.isEmpty() || !syntaxTestErrors.isEmpty()) {
 1291         io_report report;
 1292         report.addInputErrors(inputErrors);
 1293         report.addOutputErrors(outputErrors);
 1294         report.addReformatErrors(reformatErrors);
 1295         report.addSyntaxTestErrors(syntaxTestErrors);
 1296 
 1297         report.exec();
 1298         if (report.removeInputErrorFiles()) {
 1299 
 1300             for (int i=0; i<inputErrors.count(); i++) {
 1301                 for (int j = 0 ; j < ui->lvInputFiles->count(); ++j) {
 1302                     if (ui->lvInputFiles->item(j)->data(Qt::UserRole).toString()==inputErrors.at(i)) {
 1303                         delete ui->lvInputFiles->item(j);
 1304                         break;
 1305                     }
 1306                 }
 1307             }
 1308         }
 1309     }
 1310 }
 1311 
 1312 void MainWindow::on_pbCopyFile2CP_clicked()
 1313 {
 1314     highlight2Clipboard(false);
 1315 }
 1316 
 1317 void MainWindow::on_browserPreview_selectionChanged(){
 1318     int blockStart=ui->browserPreview->textCursor().selectionStart();
 1319     int blockEnd=ui->browserPreview->textCursor().selectionEnd();
 1320     ui->cbCopyRange->setEnabled(blockStart!=blockEnd);
 1321 }
 1322 
 1323 void MainWindow::highlight2Clipboard(bool getDataFromCP)
 1324 {
 1325 
 1326     if ((!getDataFromCP && NULL==ui->lvInputFiles->currentItem())
 1327             || (getDataFromCP && savedClipboardContent.isEmpty())) return;
 1328 
 1329     this->setCursor(Qt::WaitCursor);
 1330 
 1331     unique_ptr<highlight::CodeGenerator> generator(
 1332         highlight::CodeGenerator::getInstance(getOutputType()));
 1333 
 1334     applyCtrlValues(generator.get(), false);
 1335 
 1336     string suffix;
 1337     QString previewFilePath = (getDataFromCP) ? "": ui->lvInputFiles->currentItem()->data(Qt::UserRole).toString();
 1338 
 1339     if (getDataFromCP) {
 1340 
 1341         suffix= getFileType((ui->comboSelectSyntax->itemData(ui->comboSelectSyntax->currentIndex())).toString().toStdString(),"");
 1342 
 1343         if (ui->cbCopyRange->isEnabled() && ui->cbCopyRange->isChecked()) {
 1344             int blockStart=ui->browserPreview->textCursor().selectionStart();
 1345             int blockEnd=ui->browserPreview->textCursor().selectionEnd();
 1346             if (blockStart != blockEnd) {
 1347                 QTextCursor selCursor=ui->browserPreview->textCursor();
 1348                 selCursor.setPosition(blockStart);
 1349                 int lineStart=selCursor.blockNumber();
 1350                 selCursor.setPosition(blockEnd-1); // -1 to enable line selection by triple click
 1351                 int lineEnd=selCursor.blockNumber() - lineStart + 1;
 1352 
 1353                 if (lineEnd>0) {
 1354                     generator->setStartingInputLine(lineStart+1);
 1355                     generator->setMaxInputLineCnt(lineEnd);
 1356                 }
 1357             }
 1358         }
 1359     } else {
 1360 
 1361 #ifdef Q_OS_WIN
 1362 
 1363         previewFilePath = getWindowsShortPath(previewFilePath);
 1364 
 1365 #endif
 1366 
 1367         string currentFile = previewFilePath.toStdString();
 1368         suffix = getFileType(getFileSuffix(currentFile), currentFile);
 1369 
 1370         QString inFileName = QFileInfo(previewFilePath).fileName();
 1371         generator->setTitle(inFileName.toStdString());
 1372     }
 1373 
 1374     QString langPath = getUserScriptPath("lang");
 1375     if (langPath.isEmpty()) {
 1376         langPath = getDistLangPath(suffix);
 1377     }
 1378 
 1379 #ifdef Q_OS_WIN
 1380         langPath = getWindowsShortPath(langPath);                
 1381 #endif
 1382 
 1383       
 1384     QString clipBoardData;
 1385 
 1386     for (int twoPass=0; twoPass<2; twoPass++) {
 1387 
 1388     if ( generator->loadLanguage(langPath.toStdString()) != highlight::LOAD_FAILED) {
 1389         
 1390         applyEncoding(generator.get(), langPath);
 1391 
 1392 
 1393         if (getDataFromCP) {
 1394             clipBoardData= QString::fromStdString( generator->generateString(savedClipboardContent.toStdString()));
 1395         } else {
 1396             clipBoardData= QString::fromStdString( generator->generateStringFromFile(previewFilePath.toStdString()));
 1397         }
 1398 
 1399         if ( twoPass==0 ) {
 1400 
 1401            if (generator->requiresTwoPassParsing()) {
 1402                    // QMessageBox::information(this, "print1", "print 1");
 1403 
 1404                    if (generator->printPersistentState(twoPassOutFile.toStdString())) {
 1405                    generator->resetSyntaxReaders();
 1406                    generator->initPluginScript(twoPassOutFile.toStdString());
 1407 
 1408                     }
 1409                continue;
 1410            } else {
 1411 
 1412                //TODO method
 1413                QClipboard *clipboard = QApplication::clipboard();
 1414                if (clipboard) {
 1415                    highlight::OutputType outputType = getOutputType();
 1416                    if ( outputType==highlight::RTF) {
 1417                        QMimeData *mimeData = new QMimeData();
 1418        #ifdef Q_OS_WIN
 1419                        mimeData->setData("Rich Text Format", clipBoardData.toLatin1());
 1420        #else
 1421                        mimeData->setData("text/rtf", clipBoardData.toLatin1());
 1422        #endif
 1423                        clipboard->setMimeData(mimeData);
 1424                    }
 1425                    else if ( (outputType==highlight::HTML || outputType==highlight::XHTML) && ui->cbHTMLPasteMIME->isChecked()) {
 1426                        QMimeData *mimeData = new QMimeData();
 1427 
 1428                        if (ui->cbEncoding->isChecked() && ui->comboEncoding->currentText().toLower()=="utf-8") {
 1429                            mimeData->setHtml(clipBoardData.toUtf8());
 1430                        } else {
 1431                            mimeData->setHtml(clipBoardData.toLatin1());
 1432                        }
 1433                        clipboard->setMimeData(mimeData);
 1434                    }
 1435                    else {
 1436                        clipboard->setText(clipBoardData);
 1437                    }
 1438                }
 1439 
 1440                break;
 1441            }
 1442        }
 1443 
 1444            //TODO method
 1445         QClipboard *clipboard = QApplication::clipboard();
 1446         if (clipboard) {
 1447             highlight::OutputType outputType = getOutputType();
 1448             if ( outputType==highlight::RTF) {
 1449                 QMimeData *mimeData = new QMimeData();
 1450 #ifdef Q_OS_WIN
 1451                 mimeData->setData("Rich Text Format", clipBoardData.toLatin1());
 1452 #else
 1453                 mimeData->setData("text/rtf", clipBoardData.toLatin1());
 1454 #endif
 1455                 clipboard->setMimeData(mimeData);
 1456             }
 1457             else if ( (outputType==highlight::HTML || outputType==highlight::XHTML) && ui->cbHTMLPasteMIME->isChecked()) {
 1458                 QMimeData *mimeData = new QMimeData();
 1459 
 1460                 if (ui->cbEncoding->isChecked() && ui->comboEncoding->currentText().toLower()=="utf-8") {
 1461                     mimeData->setHtml(clipBoardData.toUtf8());
 1462                 } else {
 1463                     mimeData->setHtml(clipBoardData.toLatin1());
 1464                 }
 1465                 clipboard->setMimeData(mimeData);
 1466             }
 1467             else {
 1468                 clipboard->setText(clipBoardData);
 1469             }
 1470         }
 1471     } else {
 1472         statusBar()->showMessage(
 1473             tr("Conversion of \"%1\" not possible.").arg((getDataFromCP)?tr("clipboard data"):previewFilePath));
 1474     }
 1475 
 1476     }
 1477 
 1478     generator->clearPersistentSnippets();
 1479     this->setCursor(Qt::ArrowCursor);
 1480 }
 1481 
 1482 void MainWindow::plausibility()
 1483 {
 1484     ui->leOutputDest->setEnabled(!ui->cbWrite2Src->isChecked());
 1485     ui->pbOutputDest->setEnabled(!ui->cbWrite2Src->isChecked());
 1486     ui->pbBrowseOutDir->setEnabled(!ui->cbWrite2Src->isChecked());
 1487 
 1488     ui->cbPadZeroes->setEnabled(ui->cbIncLineNo->isChecked());
 1489     ui->cbAdvWrapping->setEnabled(ui->cbWrapping->isChecked());
 1490     ui->sbLineLength->setEnabled(ui->cbWrapping->isChecked());
 1491     ui->cbOmitWrappedLineNumbers->setEnabled(ui->cbWrapping->isChecked());
 1492     ui->comboEncoding->setEnabled(ui->cbEncoding->isChecked());
 1493     ui->comboReformat->setEnabled(ui->cbReformat->isChecked());
 1494     ui->comboKwCase->setEnabled(ui->cbKwCase->isChecked());
 1495     ui->comboTheme->setEnabled(getUserScriptPath("theme").isEmpty());
 1496    // ui->cbUseBase16->setEnabled(getUserScriptPath("theme").isEmpty());
 1497     ui->comboSelectSyntax->setEnabled(getUserScriptPath("lang").isEmpty());
 1498 
 1499     ui->cbHTMLInlineCSS->setEnabled(ui->cbHTMLEmbedStyle->isChecked());
 1500     ui->cbHTMLFileNameAnchor->setEnabled(ui->cbHTMLAnchors->isChecked());
 1501     ui->leHTMLStyleFile->setEnabled(!ui->cbHTMLEmbedStyle->isChecked());
 1502     ui->leHTMLStyleIncFile->setEnabled(!(ui->cbHTMLInlineCSS->isEnabled() && ui->cbHTMLInlineCSS->isChecked()));
 1503     ui->pbHTMLChooseStyleIncFile->setEnabled(!(ui->cbHTMLInlineCSS->isEnabled() && ui->cbHTMLInlineCSS->isChecked()));
 1504     ui->leHTMLCssPrefix->setEnabled(!ui->cbHTMLInlineCSS->isChecked());
 1505     ui->leLATEXStyleFile->setEnabled(!ui->cbLATEXEmbedStyle->isChecked());
 1506     ui->leTEXStyleFile->setEnabled(!ui->cbTEXEmbedStyle->isChecked());
 1507     ui->leSVGStyleFile->setEnabled(!ui->cbSVGEmbedStyle->isChecked());
 1508 
 1509     ui->cbFragment->setEnabled( getOutputType()!=highlight::RTF && getOutputType()!=highlight::SVG );
 1510     ui->sbLineNoWidth->setEnabled(ui->cbIncLineNo->isChecked());
 1511     ui->sbLineNoStart->setEnabled(ui->cbIncLineNo->isChecked());
 1512     ui->cbHTMLIndex->setEnabled(!ui->cbWrite2Src->isChecked());
 1513     ui->cbHTMLEnclosePreTags->setEnabled(ui->cbFragment->isChecked());
 1514     ui->cbKeepInjections->setEnabled(ui->cbFragment->isEnabled() && ui->cbFragment->isChecked());
 1515     ui->cbHTMLAnchors->setEnabled(ui->cbIncLineNo->isChecked());
 1516     ui->cbHTMLFileNameAnchor->setEnabled(ui->cbIncLineNo->isChecked());
 1517     ui->cbHTMLOrderedList->setEnabled(ui->cbIncLineNo->isChecked());
 1518     ui->pbCopyToCP->setEnabled(!savedClipboardContent.isEmpty());
 1519 
 1520     copyShortcut->setEnabled(ui->tabIOSelection->currentWidget()==ui->tab_clipboard);
 1521     pasteShortcut->setEnabled(ui->tabIOSelection->currentWidget()==ui->tab_clipboard);
 1522 
 1523     switch (ui->comboFormat->currentIndex()) {
 1524     case 0:
 1525     case 1:
 1526         ui->stackedSpecificOptions->setCurrentIndex(0);
 1527         break;
 1528     case 2:
 1529         ui->stackedSpecificOptions->setCurrentIndex(1);
 1530         break;
 1531     case 3:
 1532         ui->stackedSpecificOptions->setCurrentIndex(2);
 1533         break;
 1534     case 4:
 1535         ui->stackedSpecificOptions->setCurrentIndex(3);
 1536         break;
 1537     case 6:
 1538         ui->stackedSpecificOptions->setCurrentIndex(4);
 1539         break;
 1540     default:
 1541         ui->stackedSpecificOptions->setCurrentIndex(5);
 1542         break;
 1543     }
 1544     ui->tabWidgetOptions->setTabText(1, tr("%1 options").arg(ui->comboFormat->currentText() ));
 1545 }
 1546 
 1547 void MainWindow::updatePreview()
 1548 {
 1549     //toggle input source flag if file is selcetd or clipboard is pasted
 1550     if (sender()== ui->pbPasteFromCB|| sender()==ui->lvInputFiles) {
 1551         getDataFromCP = sender()==ui->pbPasteFromCB;
 1552     }
 1553 
 1554     if ( ui->comboTheme->currentIndex()<0
 1555          || (!getDataFromCP && NULL==ui->lvInputFiles->currentItem())
 1556          || (getDataFromCP && savedClipboardContent.isEmpty())) return;
 1557 
 1558     int vScroll = ui->browserPreview->verticalScrollBar()->value();
 1559     int hScroll = ui->browserPreview->horizontalScrollBar()->value();
 1560     this->setCursor(Qt::WaitCursor);
 1561     highlight::HtmlGenerator pwgenerator;
 1562     pwgenerator.setIncludeStyle(true);
 1563     pwgenerator.setHTMLInlineCSS(true);
 1564     if (!getDataFromCP) {
 1565         pwgenerator.setMaxInputLineCnt(1000);
 1566     }
 1567     applyCtrlValues(&pwgenerator, true);
 1568 
 1569     string suffix;
 1570     QString previewInputPath = (getDataFromCP) ? "" : ui->lvInputFiles->currentItem()->data(Qt::UserRole).toString();
 1571     QString croppedName = QFileInfo(previewInputPath).fileName();
 1572 
 1573 #ifdef Q_OS_WIN
 1574 
 1575         previewInputPath = getWindowsShortPath(previewInputPath);
 1576 
 1577 #endif
 1578 
 1579     if (getDataFromCP) {
 1580         suffix= getFileType((ui->comboSelectSyntax->itemData(ui->comboSelectSyntax->currentIndex())).toString().toStdString(),"");
 1581     } else {
 1582         string currentFile = previewInputPath.toStdString();
 1583         suffix = getFileType(getFileSuffix(currentFile), currentFile);
 1584     }
 1585 
 1586     QString langPath = getUserScriptPath("lang");
 1587     QString langInfo=tr("(user script)");
 1588     if (langPath.isEmpty()) {
 1589         langInfo="";
 1590         langPath = getDistLangPath(suffix);
 1591     }
 1592     
 1593 #ifdef Q_OS_WIN
 1594     langPath = getWindowsShortPath(langPath);                
 1595 #endif
 1596 
 1597     QString themePath = getUserScriptPath("theme");
 1598     QString themeInfo=tr("(user script)");
 1599     QString previewData;
 1600 
 1601     if (themePath.isEmpty()) {
 1602         themeInfo="";
 1603     }
 1604 
 1605     for (int twoPass=0; twoPass<2; twoPass++) {
 1606 
 1607         if ( pwgenerator.loadLanguage(langPath.toStdString()) != highlight::LOAD_FAILED) {
 1608 
 1609             if ( twoPass==0 ) {
 1610                 langInfo.append(QString(" [%1]").arg(QString::fromStdString(pwgenerator.getSyntaxCatDescription())));
 1611                 themeInfo.append(QString(" [%1]").arg(QString::fromStdString(pwgenerator.getThemeCatDescription())));
 1612 
 1613                 ui->lbPreview->setText(tr("Preview (%1):").arg(
 1614                                            (getDataFromCP)?tr("clipboard data"):croppedName) );
 1615 
 1616                 QString syntaxDesc = tr("Current syntax: %1 %2").arg(QString::fromStdString(pwgenerator.getSyntaxDescription())).arg(langInfo);
 1617                 QString themeDesc = tr("Current theme: %1 %2").arg(QString::fromStdString(pwgenerator.getThemeDescription())).arg(themeInfo);
 1618 
 1619                 statusBar()->showMessage(QString("%1 | %2").arg(syntaxDesc, themeDesc));
 1620             }
 1621 
 1622 
 1623             // fix utf-8 data preview - to be improved (other encodings??)
 1624             if (ui->cbEncoding->isChecked() && ui->comboEncoding->currentText().toLower()=="utf-8") {
 1625                 if (getDataFromCP) {
 1626                     previewData= QString::fromUtf8( pwgenerator.generateString(savedClipboardContent.toStdString()).c_str());
 1627                 } else {
 1628                     previewData= QString::fromUtf8( pwgenerator.generateStringFromFile(previewInputPath.toStdString()).c_str());
 1629                 }
 1630             } else {
 1631                 if (getDataFromCP) {
 1632                     previewData= QString::fromStdString( pwgenerator.generateString(savedClipboardContent.toStdString()));
 1633                 } else {
 1634                     previewData= QString::fromStdString( pwgenerator.generateStringFromFile(previewInputPath.toStdString()));
 1635                 }
 1636             }
 1637 
 1638             if ( twoPass==0 ) {
 1639 
 1640                 if (pwgenerator.requiresTwoPassParsing()
 1641                    ) {
 1642                    //QMessageBox::information(this, "print2", "print 2");
 1643 
 1644                    if (pwgenerator.printPersistentState(twoPassOutFile.toStdString())) {
 1645                         pwgenerator.resetSyntaxReaders();
 1646                         pwgenerator.initPluginScript(twoPassOutFile.toStdString());
 1647                     }
 1648                     continue;
 1649                 } else {
 1650                     ui->browserPreview->setHtml(previewData);
 1651                     break;
 1652                 }
 1653             }
 1654 
 1655             ui->browserPreview->setHtml(previewData);
 1656         } else {
 1657             statusBar()->showMessage(tr("Preview of \"%1\" not possible.").arg((getDataFromCP)?tr("clipboard data"):croppedName));
 1658             break;
 1659         }
 1660     }
 1661 
 1662     pwgenerator.clearPersistentSnippets();
 1663 
 1664     ui->browserPreview->verticalScrollBar()->setValue(vScroll);
 1665     ui->browserPreview->horizontalScrollBar()->setValue(hScroll);
 1666     this->setCursor(Qt::ArrowCursor);
 1667 }
 1668 
 1669 void MainWindow::showHelpFile(const QString& file){
 1670     ShowTextFile show;
 1671     show.setFileName(file);
 1672     show.exec();
 1673 }
 1674 
 1675 void MainWindow::on_action_Manual_triggered()
 1676 {
 1677     showHelpFile("README.adoc");
 1678 }
 1679 
 1680 void MainWindow::on_action_Changelog_triggered()
 1681 {
 1682     showHelpFile("ChangeLog.adoc");
 1683 }
 1684 
 1685 void MainWindow::on_action_Plug_Ins_triggered()
 1686 {
 1687     showHelpFile("README_PLUGINS.adoc");
 1688 }
 1689 
 1690 void MainWindow::on_action_License_triggered()
 1691 {
 1692     showHelpFile("COPYING");
 1693 }
 1694 
 1695 void MainWindow::on_pbHTMLChooseStyleIncFile_clicked()
 1696 {
 1697     selectSingleFile(ui->leHTMLStyleIncFile, tr("Choose a style include file"), "*.css");
 1698 }
 1699 void MainWindow::on_pbSVGChooseStyleIncFile_clicked()
 1700 {
 1701     selectSingleFile(ui->leSVGStyleIncFile, tr("Choose a style include file"), "*.css");
 1702 }
 1703 void MainWindow::on_pbLATEXChooseStyleIncFile_clicked()
 1704 {
 1705     selectSingleFile(ui->leLATEXStyleIncFile, tr("Choose a style include file"), "*.sty");
 1706 }
 1707 
 1708 void MainWindow::on_pbTEXChooseStyleIncFile_clicked()
 1709 {
 1710     selectSingleFile(ui->leTEXStyleIncFile, tr("Choose a style include file"), "*.sty");
 1711 }
 1712 
 1713 void MainWindow::on_actionAbout_translations_triggered()
 1714 {
 1715     QMessageBox::information(this, tr("About providing translations"),
 1716                              tr("The GUI was developed using the Qt toolkit, and "
 1717                                 "translations may be provided using the tools Qt Linguist and lrelease.\n"
 1718                                 "The highlight.ts file for Linguist resides in the src/gui-qt subdirectory.\n"
 1719                                 "The qm file generated by lrelease has to be saved in gui-files/l10n.\n\n"
 1720                                 "Please send a note to as (at) andre-simon (dot) de if you have issues during translating "
 1721                                 "or if you have finished or updated a translation."));
 1722 }
 1723 
 1724 void MainWindow::dropEvent(QDropEvent *event)
 1725 {
 1726     const QMimeData *mimeData = event->mimeData();
 1727 
 1728     if (mimeData && mimeData->hasUrls()) {
 1729         QList<QUrl> urlList = mimeData->urls();
 1730         QStringList localURLs;
 1731         for (int i = 0; i < urlList.size(); ++i) {
 1732             localURLs << urlList.at(i).toLocalFile();
 1733         }
 1734         addToView(localURLs, ui->lvInputFiles);
 1735     }
 1736     event->acceptProposedAction();
 1737 }
 1738 
 1739 void MainWindow::dragEnterEvent(QDragEnterEvent *event)
 1740 {
 1741     event->acceptProposedAction();
 1742 }
 1743 
 1744 void MainWindow::dragMoveEvent(QDragMoveEvent *event)
 1745 {
 1746     event->acceptProposedAction();
 1747 }
 1748 
 1749 void MainWindow::dragLeaveEvent(QDragLeaveEvent *event)
 1750 {
 1751     event->accept();
 1752 }
 1753 
 1754 void MainWindow::on_pbPasteFromCB_clicked()
 1755 {
 1756     QClipboard *clipboard = QApplication::clipboard();
 1757     if (clipboard) {
 1758         savedClipboardContent = clipboard->text();
 1759         updatePreview();
 1760         ui->pbCopyToCP->setEnabled(!savedClipboardContent.isEmpty());
 1761     }
 1762 }
 1763 
 1764 void MainWindow::on_pbCopyToCP_clicked()
 1765 {
 1766     highlight2Clipboard(true);
 1767 }
 1768 
 1769 void MainWindow::on_pbSelectPlugin_clicked()
 1770 {
 1771     QString pluginsPath = getDistPluginPath();
 1772     QStringList files = QFileDialog::getOpenFileNames(
 1773                             this,
 1774                             tr("Select one or more plug-ins"),
 1775                             pluginsPath,
 1776                             "*.lua");
 1777 
 1778     addToView(files, ui->lvPluginScripts, ":/plugin.png",  true, true);
 1779 }
 1780 
 1781 void MainWindow::on_pbSelectScript_clicked()
 1782 {
 1783     QStringList files = QFileDialog::getOpenFileNames(
 1784                             this,
 1785                             tr("Select one or more syntax or theme scripts"),
 1786                             "",
 1787                             "Language definitions (*.lang)\nColour themes (*.theme)");
 1788 
 1789     addToView(files, ui->lvUserScripts, ":/script.png",  true, false);
 1790 }
 1791 
 1792 void MainWindow::on_pbClearSelPlugin_clicked()
 1793 {
 1794     QList<QListWidgetItem *> selectedItems = ui->lvPluginScripts->selectedItems();
 1795     for (int i = 0; i < selectedItems.size(); ++i) {
 1796         delete selectedItems.at(i);
 1797     }
 1798     ui->lblPluginDescription->setText("");
 1799 }
 1800 
 1801 void MainWindow::on_pbClearSelScript_clicked()
 1802 {
 1803     QList<QListWidgetItem *> selectedItems = ui->lvUserScripts->selectedItems();
 1804     for (int i = 0; i < selectedItems.size(); ++i) {
 1805         scriptWatcher.removePath( ui->lvUserScripts->item(i)->data(Qt::UserRole).toString());
 1806         delete selectedItems.at(i);
 1807     }
 1808     ui->lblScriptDescription->setText("");
 1809 }
 1810 void MainWindow::on_pbClearSelection_clicked()
 1811 {
 1812     QList<QListWidgetItem *> selectedItems = ui->lvInputFiles->selectedItems();
 1813     for (int i = 0; i < selectedItems.size(); ++i) {
 1814         delete selectedItems.at(i);
 1815     }
 1816 }
 1817 
 1818 void MainWindow::on_pbClearAll_clicked()
 1819 {
 1820     ui->lvInputFiles->clear();
 1821 }
 1822 
 1823 void MainWindow::on_pbClearAllPlugins_clicked()
 1824 {
 1825     ui->lvPluginScripts->clear();
 1826 }
 1827 void MainWindow::on_pbClearAllScripts_clicked()
 1828 {
 1829     ui->lvUserScripts->clear();
 1830     scriptWatcher.removePaths(scriptWatcher.files());
 1831 }
 1832 
 1833 void MainWindow::on_actionVisit_website_triggered()
 1834 {
 1835     QDesktopServices::openUrl(QUrl("http://www.andre-simon.de/"));
 1836 }
 1837 
 1838 void MainWindow::on_actionDock_floating_panels_toggled(bool arg1)
 1839 {
 1840     ui->dockWidget->setFloating(arg1);
 1841 }
 1842 
 1843 void MainWindow::on_pbPluginReadFilePath_clicked()
 1844 {
 1845     selectSingleFile(ui->lePluginReadFilePath, tr("Choose a plug-in input file"), "*");
 1846 }
 1847 
 1848 void MainWindow::on_pbCopyAndPaste_clicked()
 1849 {
 1850     ui->pbPasteFromCB->click();
 1851     ui->pbCopyToCP->click();
 1852 }
 1853 
 1854 void MainWindow::on_pbBrowseOutDir_clicked()
 1855 {
 1856     QDesktopServices::openUrl(QUrl::fromLocalFile(ui->leOutputDest->text()));
 1857 }
 1858 
 1859 void MainWindow::on_lvUserScripts_itemClicked(QListWidgetItem *item)
 1860 {
 1861      QString scriptPath= item->data(Qt::UserRole).toString();
 1862      try {
 1863          Diluculum::LuaState ls;
 1864          ls.doFile ( scriptPath.toStdString());
 1865          ui->lblScriptDescription->setText(QString::fromStdString(ls["Description"].value().asString()));
 1866 
 1867          if (item->checkState()==Qt::Checked){
 1868              scriptWatcher.addPath(scriptPath);
 1869              QString fileExt=QFileInfo(scriptPath).completeSuffix();
 1870              QString otherScriptPath;
 1871              for (int i = 0; i < ui->lvUserScripts->count(); ++i) {
 1872                  otherScriptPath = ui->lvUserScripts->item(i)->data(Qt::UserRole).toString();
 1873                  if (ui->lvUserScripts->item(i)!=item && otherScriptPath.endsWith(fileExt)){
 1874                      ui->lvUserScripts->item(i)->setCheckState(Qt::Unchecked);
 1875                      scriptWatcher.removePath(otherScriptPath);
 1876                  }
 1877              }
 1878          } else {
 1879              scriptWatcher.removePath(scriptPath);
 1880          }
 1881      } catch (Diluculum::LuaError &err) {
 1882          QMessageBox::warning(this, "User script error", QString::fromStdString( err.what()));
 1883      }
 1884 }
 1885 
 1886 QString MainWindow::getUserScriptPath(QString type){
 1887     for (int i = 0; i < ui->lvUserScripts->count(); ++i) {
 1888         QString path=ui->lvUserScripts->item(i)->data(Qt::UserRole).toString();
 1889         if (ui->lvUserScripts->item(i)->checkState()==Qt::Checked && path.endsWith(type)){
 1890             return path;
 1891         }
 1892     }
 1893     return "";
 1894 }
 1895 
 1896 void MainWindow::on_lvPluginScripts_itemClicked(QListWidgetItem *item)
 1897 {
 1898     try {
 1899         Diluculum::LuaState ls;
 1900         //TODO Check Windows MB Path
 1901         ls.doFile ( item->data(Qt::UserRole).toString().toStdString());
 1902         ui->lblPluginDescription->setText(QString::fromStdString(ls["Description"].value().asString()));
 1903         statusBar()->showMessage(tr("Some plug-in effects may not be visible in the preview."));
 1904     } catch (Diluculum::LuaError &err) {
 1905         QMessageBox::warning(this, "Plug-In error", QString::fromStdString( err.what()));
 1906     }
 1907 }
 1908 
 1909 
 1910 QString MainWindow::getDistThemePath(){
 1911     QString themeLocation =  ui->comboThemeFilter->currentIndex() >1 ? "themes/base16" : "themes";
 1912     QString selectedTheme = ui->comboTheme->currentData().toString();
 1913 #ifdef Q_OS_OSX
 1914      return QString("%1/../Resources/%3/%2.theme").arg(
 1915                             QCoreApplication::applicationDirPath()).arg(selectedTheme, themeLocation);
 1916 #else
 1917     #ifdef DATA_DIR
 1918      return  QString("%1%3/%2.theme").arg(
 1919                             DATA_DIR).arg(selectedTheme, themeLocation);
 1920     #else
 1921      return  QString("%1/%3/%2.theme").arg(
 1922                             QDir::currentPath()).arg(selectedTheme, themeLocation);
 1923     #endif
 1924 #endif
 1925 }
 1926 
 1927 QString MainWindow::getDistLangPath(const string & suffix){
 1928 #ifdef Q_OS_OSX
 1929     return QDir::toNativeSeparators(QString("%1/../Resources/langDefs/%2.lang").arg(
 1930                            QCoreApplication::applicationDirPath()).arg(QString::fromStdString(suffix)));
 1931 #else
 1932     #ifdef DATA_DIR
 1933     return QDir::toNativeSeparators(QString("%1/langDefs/%2.lang").arg(
 1934                            DATA_DIR).arg(QString::fromStdString(suffix)));
 1935     #else
 1936     return QDir::toNativeSeparators(QString("%1/langDefs/%2.lang").arg(
 1937                            QDir::currentPath()).arg(QString::fromStdString(suffix)));
 1938     #endif
 1939 #endif
 1940 }
 1941 
 1942 QString MainWindow::getDistPluginPath(){
 1943 #ifdef Q_OS_OSX
 1944     return QString("%1/../Resources/plugins").arg(QCoreApplication::applicationDirPath());
 1945 #else
 1946     #ifdef DATA_DIR
 1947     return QDir::toNativeSeparators(QString("%1/plugins").arg(DATA_DIR));
 1948     #else
 1949     return QDir::toNativeSeparators(QString("%1/plugins").arg(QDir::currentPath()));
 1950     #endif
 1951 #endif
 1952 }
 1953 
 1954 QString MainWindow::getDistFileConfigPath(){
 1955 #ifdef Q_OS_OSX
 1956     return QDir::toNativeSeparators(QString("%1/../Resources/filetypes.conf").arg(QCoreApplication::applicationDirPath()));
 1957 #else
 1958     #ifdef CONFIG_DIR
 1959     return QDir::toNativeSeparators(QString("%1/filetypes.conf").arg(CONFIG_DIR));
 1960     #else
 1961     return QDir::toNativeSeparators(QString("%1/filetypes.conf").arg(QDir::currentPath()));
 1962     #endif
 1963 #endif
 1964 }
 1965 
 1966 QString MainWindow::getDistFileFilterPath(){
 1967 #ifdef Q_OS_OSX
 1968     return QCoreApplication::applicationDirPath()+"/../Resources/gui_files/ext/fileopenfilter.conf";
 1969 #else
 1970     #ifdef DATA_DIR
 1971     return QString(DATA_DIR) + "/gui_files/ext/fileopenfilter.conf";
 1972     #else
 1973     return QDir::currentPath()+"/gui_files/ext/fileopenfilter.conf";
 1974     #endif
 1975 #endif
 1976 }
 1977 
 1978 void MainWindow::on_comboThemeFilter_currentIndexChanged(int index)
 1979 {
 1980     if (ui->comboTheme->count())
 1981         fillThemeCombo(0);
 1982 }
 1983 
 1984 QString MainWindow::getWindowsShortPath(const QString & path){
 1985 
 1986     QString shortPath(path);
 1987 #ifdef Q_OS_WIN
 1988         int length = GetShortPathName( (const wchar_t*)path.utf16(),0,0);
 1989         wchar_t* buffer = new wchar_t[length];
 1990 
 1991         length = GetShortPathName( (const wchar_t*)path.utf16(), buffer, length);
 1992         shortPath = QString::fromUtf16((const char16_t*)buffer, length);
 1993         delete[] buffer;
 1994 #endif
 1995 
 1996     return shortPath;
 1997 }
 1998