KDevelop API Documentation

buildtools/autotools/configureoptionswidget.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2001-2002 by Bernd Gehrmann * 00003 * bernd@kdevelop.org * 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 00012 #include "configureoptionswidget.h" 00013 00014 #include <qcombobox.h> 00015 #include <qdir.h> 00016 #include <qfile.h> 00017 #include <qfileinfo.h> 00018 #include <qlabel.h> 00019 #include <qlineedit.h> 00020 #include <qpushbutton.h> 00021 #include <qtimer.h> 00022 #include <qvalidator.h> 00023 #include <kdebug.h> 00024 #include <kfiledialog.h> 00025 #include <klibloader.h> 00026 #include <klocale.h> 00027 #include <kmessagebox.h> 00028 #include <kservice.h> 00029 #include <ktrader.h> 00030 00031 #include "kdevcompileroptions.h" 00032 #include "autoprojectpart.h" 00033 00034 00035 class ServiceComboBox 00036 { 00037 public: 00038 static void insertStringList(QComboBox *combo, const QValueList<KService::Ptr> &list, 00039 QStringList *names, QStringList *execs) 00040 { 00041 QValueList<KService::Ptr>::ConstIterator it; 00042 for (it = list.begin(); it != list.end(); ++it) { 00043 combo->insertItem((*it)->comment()); 00044 (*names) << (*it)->desktopEntryName(); 00045 (*execs) << (*it)->exec(); 00046 kdDebug(9020) << "insertStringList item " << (*it)->name() << "," << (*it)->exec() << endl; 00047 } 00048 } 00049 static QString currentText(QComboBox *combo, const QStringList &names) 00050 { 00051 if (combo->currentItem() == -1) 00052 return QString::null; 00053 return names[combo->currentItem()]; 00054 } 00055 static void setCurrentText(QComboBox *combo, const QString &str, const QStringList &names) 00056 { 00057 QStringList::ConstIterator it; 00058 int i = 0; 00059 for (it = names.begin(); it != names.end(); ++it) { 00060 if (*it == str) { 00061 combo->setCurrentItem(i); 00062 break; 00063 } 00064 ++i; 00065 } 00066 } 00067 }; 00068 00069 00070 ConfigureOptionsWidget::ConfigureOptionsWidget(AutoProjectPart *part, QWidget *parent, const char *name) 00071 : ConfigureOptionsWidgetBase(parent, name) 00072 { 00073 config_combo->setValidator(new QRegExpValidator(QRegExp("^\\D.*"), this)); 00074 00075 m_part = part; 00076 00077 coffers = KTrader::self()->query("KDevelop/CompilerOptions", "[X-KDevelop-Language] == 'C'"); 00078 cxxoffers = KTrader::self()->query("KDevelop/CompilerOptions", "[X-KDevelop-Language] == 'C++'"); 00079 f77offers = KTrader::self()->query("KDevelop/CompilerOptions", "[X-KDevelop-Language] == 'Fortran'"); 00080 00081 ServiceComboBox::insertStringList(cservice_combo, coffers, &cservice_names, &cservice_execs); 00082 ServiceComboBox::insertStringList(cxxservice_combo, cxxoffers, &cxxservice_names, &cxxservice_execs); 00083 ServiceComboBox::insertStringList(f77service_combo, f77offers, &f77service_names, &f77service_execs); 00084 00085 if (coffers.isEmpty()) 00086 cflags_button->setEnabled(false); 00087 if (cxxoffers.isEmpty()) 00088 cxxflags_button->setEnabled(false); 00089 if (f77offers.isEmpty()) 00090 f77flags_button->setEnabled(false); 00091 00092 allConfigs = part->allBuildConfigs(); 00093 config_combo->insertStringList(allConfigs); 00094 00095 dirty = false; 00096 currentConfig = QString::null; 00097 configChanged(part->currentBuildConfig()); 00098 00099 fixLayout(); 00100 } 00101 00102 00103 ConfigureOptionsWidget::~ConfigureOptionsWidget() 00104 {} 00105 00106 00107 void ConfigureOptionsWidget::fixLayout() 00108 { 00109 int w1 = ccompiler_label->sizeHint().width(); 00110 int w2 = cbinary_label->sizeHint().width(); 00111 int w3 = cflags_label->sizeHint().width(); 00112 int w4 = cxxcompiler_label->sizeHint().width(); 00113 int w5 = cxxbinary_label->sizeHint().width(); 00114 int w6 = cxxflags_label->sizeHint().width(); 00115 int w7 = f77compiler_label->sizeHint().width(); 00116 int w8 = f77binary_label->sizeHint().width(); 00117 int w9 = f77flags_label->sizeHint().width(); 00118 00119 int w = QMAX(w1, QMAX(w2, w3)); 00120 w = QMAX(w, QMAX(w4, w5)); 00121 w = QMAX(w, QMAX(w6, w7)); 00122 w = QMAX(w, QMAX(w8, w9)); 00123 00124 ccompiler_label->setMinimumWidth(w); 00125 cxxcompiler_label->setMinimumWidth(w); 00126 f77compiler_label->setMinimumWidth(w); 00127 } 00128 00129 00130 void ConfigureOptionsWidget::readSettings(const QString &config) 00131 { 00132 QDomDocument dom = *m_part->projectDom(); 00133 QString prefix = "/kdevautoproject/configurations/" + config + "/"; 00134 kdDebug(9020) << "Reading config from " << prefix << endl; 00135 00136 configargs_edit->setText(DomUtil::readEntry(dom, prefix + "configargs")); 00137 QString builddir = DomUtil::readEntry(dom, prefix + "builddir"); 00138 if (builddir.isEmpty() && config != "default") 00139 builddir = config; 00140 builddir_edit->setText(builddir); 00141 00142 topsourcedir_edit->setText(DomUtil::readEntry(dom, prefix + "topsourcedir")); 00143 00144 cppflags_edit->setText(DomUtil::readEntry(dom, prefix + "cppflags")); 00145 ldflags_edit->setText(DomUtil::readEntry(dom, prefix + "ldflags")); 00146 00147 QString ccompiler = DomUtil::readEntry(dom, prefix + "ccompiler"); 00148 QString cxxcompiler = DomUtil::readEntry(dom, prefix + "cxxcompiler"); 00149 QString f77compiler = DomUtil::readEntry(dom, prefix + "f77compiler"); 00150 00151 if (ccompiler.isEmpty()) { 00152 kdDebug(9020) << "No c compiler set" << endl; 00153 QValueList<KService::Ptr>::ConstIterator it; 00154 for (it = coffers.begin(); it != coffers.end(); ++it) { 00155 if ((*it)->property("X-KDevelop-Default").toBool()) { 00156 kdDebug(9020) << "Found default " << (*it)->name() << endl; 00157 ccompiler = (*it)->name(); 00158 break; 00159 } 00160 } 00161 } 00162 if (cxxcompiler.isEmpty()) { 00163 kdDebug(9020) << "No cxx compiler set" << endl; 00164 QValueList<KService::Ptr>::ConstIterator it; 00165 for (it = cxxoffers.begin(); it != cxxoffers.end(); ++it) { 00166 if ((*it)->property("X-KDevelop-Default").toBool()) { 00167 kdDebug(9020) << "Found default " << (*it)->name() << endl; 00168 cxxcompiler = (*it)->name(); 00169 break; 00170 } 00171 } 00172 } 00173 if (f77compiler.isEmpty()) { 00174 kdDebug(9020) << "No c compiler set" << endl; 00175 QValueList<KService::Ptr>::ConstIterator it; 00176 for (it = f77offers.begin(); it != f77offers.end(); ++it) { 00177 if ((*it)->property("X-KDevelop-Default").toBool()) { 00178 kdDebug(9020) << "Found default " << (*it)->name() << endl; 00179 f77compiler = (*it)->name(); 00180 break; 00181 } 00182 } 00183 } 00184 00185 ServiceComboBox::setCurrentText(cservice_combo, ccompiler, cservice_names); 00186 ServiceComboBox::setCurrentText(cxxservice_combo, cxxcompiler, cxxservice_names); 00187 ServiceComboBox::setCurrentText(f77service_combo, f77compiler, f77service_names); 00188 00189 cbinary_edit->setText(DomUtil::readEntry(dom, prefix + "ccompilerbinary")); 00190 cxxbinary_edit->setText(DomUtil::readEntry(dom, prefix + "cxxcompilerbinary")); 00191 f77binary_edit->setText(DomUtil::readEntry(dom, prefix + "f77compilerbinary")); 00192 00193 cflags_edit->setText(DomUtil::readEntry(dom, prefix + "cflags")); 00194 cxxflags_edit->setText(DomUtil::readEntry(dom, prefix + "cxxflags")); 00195 f77flags_edit->setText(DomUtil::readEntry(dom, prefix + "f77flags")); 00196 } 00197 00198 00199 void ConfigureOptionsWidget::saveSettings(const QString &config) 00200 { 00201 QDomDocument dom = *m_part->projectDom(); 00202 QString prefix = "/kdevautoproject/configurations/" + config + "/"; 00203 kdDebug(9020) << "Saving config under " << prefix << endl; 00204 00205 DomUtil::writeEntry(dom, prefix + "configargs", configargs_edit->text()); 00206 DomUtil::writeEntry(dom, prefix + "builddir", builddir_edit->text()); 00207 DomUtil::writeEntry(dom, prefix + "topsourcedir", topsourcedir_edit->text()); 00208 00209 DomUtil::writeEntry(dom, prefix + "cppflags", cppflags_edit->text()); 00210 DomUtil::writeEntry(dom, prefix + "ldflags", ldflags_edit->text()); 00211 00212 QFileInfo fi(m_part->buildDirectory()); 00213 QDir dir(fi.dir()); 00214 dir.mkdir(fi.fileName()); 00215 00216 DomUtil::writeEntry(dom, prefix + "ccompiler", 00217 ServiceComboBox::currentText(cservice_combo, cservice_names)); 00218 DomUtil::writeEntry(dom, prefix + "cxxcompiler", 00219 ServiceComboBox::currentText(cxxservice_combo, cxxservice_names)); 00220 DomUtil::writeEntry(dom, prefix + "f77compiler", 00221 ServiceComboBox::currentText(f77service_combo, f77service_names)); 00222 00223 DomUtil::writeEntry(dom, prefix + "ccompilerbinary", cbinary_edit->text()); 00224 DomUtil::writeEntry(dom, prefix + "cxxcompilerbinary", cxxbinary_edit->text()); 00225 DomUtil::writeEntry(dom, prefix + "f77compilerbinary", f77binary_edit->text()); 00226 00227 DomUtil::writeEntry(dom, prefix + "cflags", cflags_edit->text()); 00228 DomUtil::writeEntry(dom, prefix + "cxxflags", cxxflags_edit->text()); 00229 DomUtil::writeEntry(dom, prefix + "f77flags", f77flags_edit->text()); 00230 00231 if (KMessageBox::questionYesNo(this, i18n("Re-run configure for %1 now?").arg(config)) == KMessageBox::Yes) 00232 QTimer::singleShot(0, m_part, SLOT(slotConfigure())); 00233 } 00234 00235 00236 void ConfigureOptionsWidget::setDirty() 00237 { 00238 kdDebug(9020) << "config dirty" << endl; 00239 dirty = true; 00240 } 00241 00242 00243 void ConfigureOptionsWidget::builddirClicked() 00244 { 00245 QString dir = builddir_edit->text(); 00246 dir = KFileDialog::getExistingDirectory(dir, this); 00247 if (!dir.isNull()) 00248 builddir_edit->setText(dir); 00249 } 00250 00251 void ConfigureOptionsWidget::topsourcedirClicked() 00252 { 00253 QString dir = topsourcedir_edit->text(); 00254 dir = KFileDialog::getExistingDirectory(dir, this); 00255 if (!dir.isNull()) 00256 topsourcedir_edit->setText(dir); 00257 } 00258 00259 void ConfigureOptionsWidget::configComboTextChanged(const QString &config) 00260 { 00261 bool canAdd = !allConfigs.contains(config) && !config.contains("/") && !config.isEmpty(); 00262 bool canRemove = allConfigs.contains(config) && config != "default"; 00263 addconfig_button->setEnabled(canAdd); 00264 removeconfig_button->setEnabled(canRemove); 00265 } 00266 00267 00268 void ConfigureOptionsWidget::configChanged(const QString &config) 00269 { 00270 if (config == currentConfig || !allConfigs.contains(config)) 00271 return; 00272 00273 if (!currentConfig.isNull() && dirty) 00274 saveSettings(currentConfig); 00275 00276 currentConfig = config; 00277 readSettings(config); 00278 dirty = false; 00279 00280 config_combo->blockSignals(true); 00281 config_combo->setEditText(config); 00282 config_combo->blockSignals(false); 00283 } 00284 00285 00286 void ConfigureOptionsWidget::configAdded() 00287 { 00288 QString config = config_combo->currentText(); 00289 00290 allConfigs.append(config); 00291 00292 config_combo->clear(); 00293 config_combo->insertStringList(allConfigs); 00294 configChanged(config); 00295 setDirty(); // force saving 00296 } 00297 00298 00299 void ConfigureOptionsWidget::configRemoved() 00300 { 00301 QString config = config_combo->currentText(); 00302 00303 QDomDocument dom = *m_part->projectDom(); 00304 QDomNode node = dom.documentElement().namedItem("kdevautoproject").namedItem("configurations"); 00305 node.removeChild(node.namedItem(config)); 00306 allConfigs.remove(config); 00307 00308 config_combo->clear(); 00309 config_combo->insertStringList(allConfigs); 00310 00311 currentConfig = QString::null; 00312 configChanged("default"); 00313 } 00314 00315 00316 void ConfigureOptionsWidget::cserviceChanged() 00317 { 00318 QString exec = ServiceComboBox::currentText(cservice_combo, cservice_execs); 00319 cbinary_edit->setText(exec); 00320 kdDebug(9020) << "exec: " << exec << endl; 00321 } 00322 00323 00324 void ConfigureOptionsWidget::cxxserviceChanged() 00325 { 00326 QString exec = ServiceComboBox::currentText(cxxservice_combo, cxxservice_execs); 00327 cxxbinary_edit->setText(exec); 00328 } 00329 00330 00331 void ConfigureOptionsWidget::f77serviceChanged() 00332 { 00333 QString exec = ServiceComboBox::currentText(f77service_combo, f77service_execs); 00334 f77binary_edit->setText(exec); 00335 kdDebug(9020) << "exec: " << exec << endl; 00336 } 00337 00338 00339 void ConfigureOptionsWidget::cflagsClicked() 00340 { 00341 QString name = ServiceComboBox::currentText(cservice_combo, cservice_names); 00342 KDevCompilerOptions *plugin = createCompilerOptions(name); 00343 00344 if (plugin) { 00345 QString flags = plugin->exec(this, cflags_edit->text()); 00346 cflags_edit->setText(flags); 00347 delete plugin; 00348 } 00349 } 00350 00351 00352 void ConfigureOptionsWidget::cxxflagsClicked() 00353 { 00354 QString name = ServiceComboBox::currentText(cxxservice_combo, cxxservice_names); 00355 KDevCompilerOptions *plugin = createCompilerOptions(name); 00356 00357 if (plugin) { 00358 QString flags = plugin->exec(this, cxxflags_edit->text()); 00359 cxxflags_edit->setText(flags); 00360 delete plugin; 00361 } 00362 } 00363 00364 00365 void ConfigureOptionsWidget::f77flagsClicked() 00366 { 00367 QString name = ServiceComboBox::currentText(f77service_combo, f77service_names); 00368 KDevCompilerOptions *plugin = createCompilerOptions(name); 00369 00370 if (plugin) { 00371 QString flags = plugin->exec(this, f77flags_edit->text()); 00372 f77flags_edit->setText(flags); 00373 delete plugin; 00374 } 00375 } 00376 00377 00378 KDevCompilerOptions *ConfigureOptionsWidget::createCompilerOptions(const QString &name) 00379 { 00380 KService::Ptr service = KService::serviceByDesktopName(name); 00381 if (!service) { 00382 kdDebug(9020) << "Can't find service " << name; 00383 return 0; 00384 } 00385 00386 KLibFactory *factory = KLibLoader::self()->factory(QFile::encodeName(service->library())); 00387 if (!factory) { 00388 QString errorMessage = KLibLoader::self()->lastErrorMessage(); 00389 KMessageBox::error(0, i18n("There was an error loading the module %1.\n" 00390 "The diagnostics is:\n%2").arg(service->name()).arg(errorMessage)); 00391 exit(1); 00392 } 00393 00394 QStringList args; 00395 QVariant prop = service->property("X-KDevelop-Args"); 00396 if (prop.isValid()) 00397 args = QStringList::split(" ", prop.toString()); 00398 00399 QObject *obj = factory->create(this, service->name().latin1(), 00400 "KDevCompilerOptions", args); 00401 00402 if (!obj->inherits("KDevCompilerOptions")) { 00403 kdDebug(9020) << "Component does not inherit KDevCompilerOptions" << endl; 00404 return 0; 00405 } 00406 KDevCompilerOptions *dlg = (KDevCompilerOptions*) obj; 00407 00408 return dlg; 00409 } 00410 00411 00412 void ConfigureOptionsWidget::accept() 00413 { 00414 DomUtil::writeEntry(*m_part->projectDom(), "/kdevautoproject/general/useconfiguration", currentConfig); 00415 if (dirty) 00416 { 00417 saveSettings(currentConfig); 00418 } 00419 } 00420 00421 #include "configureoptionswidget.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:38:53 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003