00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
#include <kurlrequester.h>
00018
#include <kservice.h>
00019
#include <kdebug.h>
00020
#include <kmessagebox.h>
00021
#include <klocale.h>
00022
00023
#include <qlineedit.h>
00024
#include <qcombobox.h>
00025
#include <qregexp.h>
00026
#include <qvalidator.h>
00027
00028
#include "domutil.h"
00029
#include "kdevcompileroptions.h"
00030
00031
#include "haskellproject_part.h"
00032
#include "haskellprojectoptionsdlg.h"
00033
00034 HaskellProjectOptionsDlg::HaskellProjectOptionsDlg(
HaskellProjectPart *part,
QWidget* parent,
00035
const char* name, WFlags fl )
00036 :
HaskellProjectOptionsDlgBase( parent, name, fl ),
00037 _part( part )
00038 {
00039 config_combo->setValidator(
new QRegExpValidator(
QRegExp(
"^\\D.*" ),
this ) );
00040
00041
offers = KTrader::self()->query(
"KDevelop/CompilerOptions",
00042
"[X-KDevelop-Language] == 'Haskell'" );
00043
insertServicesIntoDlg(
offers );
00044
00045
if (
offers.isEmpty() ) {
00046 options_button->setEnabled(
false);
00047 }
00048
00049
_allConfigs =
allBuildConfigs();
00050 config_combo->insertStringList(
_allConfigs );
00051
00052
_dirty =
false;
00053
00054
QDomDocument &dom = *(
_part->
projectDom() );
00055
_currentConfig = QString::null;
00056
configChanged(DomUtil::readEntry(dom,
00057
"/kdevhaskellproject/general/useconfiguration",
00058
"default" ) );
00059 }
00060
00061 HaskellProjectOptionsDlg::~HaskellProjectOptionsDlg()
00062 {
00063 }
00064
00065 QStringList HaskellProjectOptionsDlg::allBuildConfigs()
00066 {
00067
QDomDocument &dom = *(
_part->
projectDom());
00068
00069
QStringList allConfigs;
00070 allConfigs.append(
"default");
00071
00072
QDomNode node = dom.documentElement().namedItem(
"kdevhaskellproject").namedItem(
"configurations");
00073
QDomElement childEl = node.firstChild().toElement();
00074
00075
while (!childEl.isNull()) {
00076
QString config = childEl.tagName();
00077
kdDebug() <<
"Found config " << config <<
endl;
00078
if (config !=
"default")
00079 allConfigs.append(config);
00080 childEl = childEl.nextSibling().toElement();
00081 }
00082
00083
return allConfigs;
00084 }
00085
00086 void HaskellProjectOptionsDlg::accept()
00087 {
00088 DomUtil::writeEntry(*
_part->
projectDom(),
00089
"/kdevhaskellproject/general/useconfiguration",
00090
_currentConfig);
00091
if (
_dirty)
00092 {
00093
saveConfig(
_currentConfig);
00094 }
00095 }
00096
00097 void HaskellProjectOptionsDlg::compiler_box_activated(
const QString& )
00098 {
00099
QString exec =
currentCompBoxText(
_serviceExecs );
00100 exec_edit->setText( exec );
00101 }
00102
00103 void HaskellProjectOptionsDlg::saveConfig(
QString config )
00104 {
00105
QDomDocument dom = *
_part->
projectDom();
00106
QString prefix =
"/kdevhaskellproject/configurations/" + config +
"/";
00107
00108 DomUtil::writeEntry( dom, prefix +
"compiler",
00109
currentCompBoxText(
_serviceNames ) );
00110 DomUtil::writeEntry( dom, prefix +
"compileroptions", options_edit->text());
00111 DomUtil::writeEntry( dom, prefix +
"compilerexec", exec_edit->text() );
00112 DomUtil::writeEntry( dom, prefix +
"mainsource",
00113 mainSourceUrl->
url().replace(
QRegExp(
_part->
projectDirectory() +
00114
QString(
"/" ) ),
"" ) );
00115 }
00116
00117 void HaskellProjectOptionsDlg::readConfig(
QString config )
00118 {
00119
QDomDocument dom = *
_part->
projectDom();
00120
QString prefix =
"/kdevhaskellproject/configurations/" + config +
"/";
00121
00122
QString compiler = DomUtil::readEntry(dom, prefix +
"compiler",
"");
00123
00124
if (compiler.isEmpty())
00125 {
00126
offers = KTrader::self()->query(
"KDevelop/CompilerOptions",
"[X-KDevelop-Language] == 'Haskell'");
00127
QValueList<KService::Ptr>::ConstIterator it;
00128
for (it =
offers.begin(); it !=
offers.end(); ++it) {
00129
if ((*it)->property(
"X-KDevelop-Default").toBool()) {
00130 compiler = (*it)->name();
00131
kdDebug() <<
"compiler is " << compiler <<
endl;
00132
break;
00133 }
00134 }
00135 }
00136
setCurrentCompBoxText( compiler,
_serviceNames );
00137
00138
QString exec = DomUtil::readEntry(dom, prefix +
"compilerexec",
"");
00139
if (exec.isEmpty())
00140 exec =
currentCompBoxText(
_serviceExecs );
00141 exec_edit->setText(exec);
00142 options_edit->setText(DomUtil::readEntry(dom, prefix +
"compileroptions"));
00143 mainSourceUrl->
setURL(
_part->
projectDirectory() +
"/"
00144 + DomUtil::readEntry(dom, prefix +
"mainsource") );
00145 }
00146
00147 void HaskellProjectOptionsDlg::configComboTextChanged(
const QString &config)
00148 {
00149
bool canAdd = !
_allConfigs.contains(config) && !config.contains(
"/")
00150 && !config.isEmpty();
00151
bool canRemove =
_allConfigs.contains(config) && config !=
"default";
00152 addconfig_button->setEnabled(canAdd);
00153 removeconfig_button->setEnabled(canRemove);
00154 }
00155
00156
00157 void HaskellProjectOptionsDlg::configChanged(
const QString &config)
00158 {
00159
if (config ==
_currentConfig || !
_allConfigs.contains(config))
00160
return;
00161
00162
if (!
_currentConfig.isNull() &&
_dirty)
00163
saveConfig(
_currentConfig);
00164
00165
_currentConfig = config;
00166
readConfig(config);
00167
_dirty =
false;
00168
00169 config_combo->blockSignals(
true);
00170 config_combo->setEditText(config);
00171 config_combo->blockSignals(
false);
00172 }
00173
00174
00175 void HaskellProjectOptionsDlg::configAdded()
00176 {
00177
QString config = config_combo->currentText();
00178
00179
_allConfigs.append(config);
00180
00181 config_combo->clear();
00182 config_combo->insertStringList(
_allConfigs);
00183
configChanged(config);
00184
setDirty();
00185 }
00186
00187
00188 void HaskellProjectOptionsDlg::configRemoved()
00189 {
00190
QString config = config_combo->currentText();
00191
00192
QDomDocument dom = *
_part->
projectDom();
00193
QDomNode node = dom.documentElement().namedItem(
"kdevhaskellproject" ).namedItem(
"configurations");
00194 node.removeChild(node.namedItem(config));
00195
_allConfigs.remove(config);
00196
00197 config_combo->clear();
00198 config_combo->insertStringList(
_allConfigs );
00199
00200
_currentConfig = QString::null;
00201
configChanged(
"default" );
00202 }
00203
00204 void HaskellProjectOptionsDlg::optionsButtonClicked( )
00205 {
00206
QString name =
currentCompBoxText(
_serviceNames );
00207
KDevCompilerOptions *plugin =
_part->
createCompilerOptions( name );
00208
00209
if ( plugin ) {
00210
QString flags = plugin->
exec(
this, options_edit->text());
00211 options_edit->setText(flags);
00212
delete plugin;
00213 }
00214 }
00215
00216 void HaskellProjectOptionsDlg::setDirty( )
00217 {
00218
_dirty =
true;
00219 }
00220
00221 void HaskellProjectOptionsDlg::setDefaultOptions( )
00222 {
00223
00224
if (!compiler_box->currentText().isEmpty()) {
00225 options_edit->setText(
_part->
defaultOptions( compiler_box->currentText() ) );
00226 }
00227 }
00228
00229 void HaskellProjectOptionsDlg::insertServicesIntoDlg(
const QValueList<KService::Ptr> &list )
00230 {
00231
QValueList<KService::Ptr>::ConstIterator it;
00232
for( it = list.begin(); it != list.end(); ++it ) {
00233 compiler_box->insertItem( (*it)->comment() );
00234
_serviceNames << (*it)->name();
00235
_serviceExecs << (*it)->exec();
00236
kdDebug() <<
"insertStringList item " << (*it)->name() <<
"," << (*it)->exec() <<
endl;
00237 }
00238 }
00239
00240 QString HaskellProjectOptionsDlg::currentCompBoxText(
const QStringList &names )
00241 {
00242
if( compiler_box->currentItem() == -1 ) {
00243
return QString::null;
00244 }
00245
else {
00246
return names[compiler_box->currentItem()];
00247 }
00248 }
00249
00250
00251 void HaskellProjectOptionsDlg::setCurrentCompBoxText(
const QString &str,
const QStringList &names)
00252 {
00253 QStringList::ConstIterator it;
00254
int i = 0;
00255
for (it = names.begin(); it != names.end(); ++it) {
00256
if (*it == str) {
00257 compiler_box->setCurrentItem(i);
00258
break;
00259 }
00260 ++i;
00261 }
00262 }
00263
00264 QString HaskellProjectOptionsDlg::defaultCompiler()
00265 {
00266 KTrader::OfferList
offers = KTrader::self()->query(
"KDevelop/CompilerOptions",
"[X-KDevelop-Language] == 'Haskell'");
00267
QValueList<KService::Ptr>::ConstIterator it;
00268
for (it = offers.begin(); it != offers.end(); ++it) {
00269
if ((*it)->property(
"X-KDevelop-Default").toBool()) {
00270
return (*it)->name();;
00271 }
00272 }
00273
return "";
00274 }
00275
00276 int HaskellProjectOptionsDlg::itemForText(
const QString &str,
const QStringList &names)
00277 {
00278 QStringList::ConstIterator it;
00279
int i = 0;
00280
for( it = names.begin(); it != names.end(); ++it ) {
00281
if( *it == str ) {
00282
return i;
00283 }
00284 ++i;
00285 }
00286
return 0;
00287 }
00288
00289
#include "haskellprojectoptionsdlg.moc"