KDevelop API Documentation

adaprojectoptionsdlg.cpp

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