KDevelop API Documentation

pascalprojectoptionsdlg.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 Alexander Dymo                                     *
00003  *   cloudtemple@mksat.net                                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  ***************************************************************************/
00011 #include <kurlrequester.h>
00012 #include <kservice.h>
00013 #include <kdebug.h>
00014 #include <kmessagebox.h>
00015 #include <klocale.h>
00016 
00017 #include <qlineedit.h>
00018 #include <qcombobox.h>
00019 #include <qregexp.h>
00020 #include <qvalidator.h>
00021 
00022 #include "domutil.h"
00023 #include "kdevcompileroptions.h"
00024 
00025 #include "service.h"
00026 #include "pascalproject_part.h"
00027 #include "pascalprojectoptionsdlg.h"
00028 
00029 PascalProjectOptionsDlg::PascalProjectOptionsDlg(PascalProjectPart *part, QWidget* parent, const char* name, WFlags fl)
00030     : PascalProjectOptionsDlgBase(parent,name, fl), m_part(part)
00031 {
00032     config_combo->setValidator(new QRegExpValidator(QRegExp("^\\D.*"), this));
00033 
00034     offers = KTrader::self()->query("KDevelop/CompilerOptions", "[X-KDevelop-Language] == 'Pascal'");
00035 
00036     ServiceComboBox::insertStringList(compiler_box, offers, &service_names, &service_execs);
00037 
00038     if (offers.isEmpty())
00039         options_button->setEnabled(false);
00040 
00041     allConfigs = allBuildConfigs();
00042     config_combo->insertStringList(allConfigs);
00043 
00044     dirty = false;
00045 
00046     QDomDocument &dom = *(m_part->projectDom());
00047     currentConfig = QString::null;
00048     configChanged(DomUtil::readEntry(dom, "/kdevpascalproject/general/useconfiguration", "default"));
00049 }
00050 
00051 PascalProjectOptionsDlg::~PascalProjectOptionsDlg()
00052 {
00053 }
00054 
00055 QStringList PascalProjectOptionsDlg::allBuildConfigs()
00056 {
00057     QDomDocument &dom = *(m_part->projectDom());
00058 
00059     QStringList allConfigs;
00060     allConfigs.append("default");
00061 
00062     QDomNode node = dom.documentElement().namedItem("kdevpascalproject").namedItem("configurations");
00063     QDomElement childEl = node.firstChild().toElement();
00064     while (!childEl.isNull()) {
00065         QString config = childEl.tagName();
00066         kdDebug() << "Found config " << config << endl;
00067         if (config != "default")
00068             allConfigs.append(config);
00069         childEl = childEl.nextSibling().toElement();
00070     }
00071 
00072     return allConfigs;
00073 }
00074 
00075 void PascalProjectOptionsDlg::accept()
00076 {
00077     DomUtil::writeEntry(*m_part->projectDom(), "/kdevpascalproject/general/useconfiguration", currentConfig);
00078     if (dirty)
00079     {
00080         saveConfig(currentConfig);
00081     }
00082 }
00083 
00084 void PascalProjectOptionsDlg::compiler_box_activated( const QString& /*s*/ )
00085 {
00086     QString exec = ServiceComboBox::currentText(compiler_box, service_execs);
00087     exec_edit->setText(exec);
00088 }
00089 
00090 void PascalProjectOptionsDlg::saveConfig( QString config )
00091 {
00092     QDomDocument dom = *m_part->projectDom();
00093     QString prefix = "/kdevpascalproject/configurations/" + config + "/";
00094 
00095     DomUtil::writeEntry(dom, prefix + "compiler",
00096                         ServiceComboBox::currentText(compiler_box, service_names));
00097     DomUtil::writeEntry(dom, prefix + "compileroptions", options_edit->text());
00098     DomUtil::writeEntry(dom, prefix + "compilerexec", exec_edit->text());
00099     DomUtil::writeEntry(dom, prefix + "mainsource", mainSourceUrl->url().replace(QRegExp(m_part->projectDirectory() + QString("/")),""));
00100 }
00101 
00102 void PascalProjectOptionsDlg::readConfig( QString config )
00103 {
00104     QDomDocument dom = *m_part->projectDom();
00105     QString prefix = "/kdevpascalproject/configurations/" + config + "/";
00106 
00107     QString compiler = DomUtil::readEntry(dom, prefix + "compiler", "");
00108 
00109     if (compiler.isEmpty())
00110     {
00111         offers = KTrader::self()->query("KDevelop/CompilerOptions", "[X-KDevelop-Language] == 'Pascal'");
00112         QValueList<KService::Ptr>::ConstIterator it;
00113         for (it = offers.begin(); it != offers.end(); ++it) {
00114             if ((*it)->property("X-KDevelop-Default").toBool()) {
00115                 compiler = (*it)->name();
00116                 kdDebug() << "compiler is " << compiler << endl;
00117                 break;
00118             }
00119         }
00120     }
00121     ServiceComboBox::setCurrentText(compiler_box, compiler, service_names);
00122 
00123     QString exec = DomUtil::readEntry(dom, prefix + "compilerexec", "");
00124     if (exec.isEmpty())
00125         exec = ServiceComboBox::currentText(compiler_box, service_execs);
00126     exec_edit->setText(exec);
00127     options_edit->setText(DomUtil::readEntry(dom, prefix + "compileroptions"));
00128     mainSourceUrl->setURL(m_part->projectDirectory() + "/" + DomUtil::readEntry(dom, prefix + "mainsource"));
00129 }
00130 
00131 void PascalProjectOptionsDlg::configComboTextChanged(const QString &config)
00132 {
00133     bool canAdd = !allConfigs.contains(config) && !config.contains("/") && !config.isEmpty();
00134     bool canRemove = allConfigs.contains(config) && config != "default";
00135     addconfig_button->setEnabled(canAdd);
00136     removeconfig_button->setEnabled(canRemove);
00137 }
00138 
00139 
00140 void PascalProjectOptionsDlg::configChanged(const QString &config)
00141 {
00142     if (config == currentConfig || !allConfigs.contains(config))
00143         return;
00144 
00145     if (!currentConfig.isNull() && dirty)
00146         saveConfig(currentConfig);
00147 
00148     currentConfig = config;
00149     readConfig(config);
00150     dirty = false;
00151 
00152     config_combo->blockSignals(true);
00153     config_combo->setEditText(config);
00154     config_combo->blockSignals(false);
00155 }
00156 
00157 
00158 void PascalProjectOptionsDlg::configAdded()
00159 {
00160     QString config = config_combo->currentText();
00161 
00162     allConfigs.append(config);
00163 
00164     config_combo->clear();
00165     config_combo->insertStringList(allConfigs);
00166     configChanged(config);
00167     setDirty(); // force saving
00168 }
00169 
00170 
00171 void PascalProjectOptionsDlg::configRemoved()
00172 {
00173     QString config = config_combo->currentText();
00174 
00175     QDomDocument dom = *m_part->projectDom();
00176     QDomNode node = dom.documentElement().namedItem("kdevpascalproject").namedItem("configurations");
00177     node.removeChild(node.namedItem(config));
00178     allConfigs.remove(config);
00179 
00180     config_combo->clear();
00181     config_combo->insertStringList(allConfigs);
00182 
00183     currentConfig = QString::null;
00184     configChanged("default");
00185 }
00186 
00187 void PascalProjectOptionsDlg::optionsButtonClicked( )
00188 {
00189     QString name = ServiceComboBox::currentText(compiler_box, service_names);
00190     KDevCompilerOptions *plugin = m_part->createCompilerOptions(name);
00191 
00192     if (plugin) {
00193         QString flags = plugin->exec(this, options_edit->text());
00194         options_edit->setText(flags);
00195         delete plugin;
00196     }
00197 }
00198 
00199 void PascalProjectOptionsDlg::setDirty( )
00200 {
00201     dirty = true;
00202 }
00203 
00204 void PascalProjectOptionsDlg::setDefaultOptions( )
00205 {
00206     if (!compiler_box->currentText().isEmpty())
00207         options_edit->setText(m_part->defaultOptions(compiler_box->currentText()));
00208 }
00209 
00210 #include "pascalprojectoptionsdlg.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:22 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003