KDevelop API Documentation

buildtools/autotools/addtargetdlg.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2001 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 "addtargetdlg.h" 00013 00014 #include <qcheckbox.h> 00015 #include <qcombobox.h> 00016 #include <qgroupbox.h> 00017 #include <qlineedit.h> 00018 #include <qvalidator.h> 00019 00020 #include <klocale.h> 00021 #include <kmessagebox.h> 00022 #include <ksqueezedtextlabel.h> 00023 00024 #include "autolistviewitems.h" 00025 00026 #include "misc.h" 00027 #include "autodetailsview.h" 00028 #include "autoprojectwidget.h" 00029 00030 00031 AddTargetDialog::AddTargetDialog(AutoProjectWidget *widget, SubprojectItem *item, 00032 QWidget *parent, const char *name) 00033 : AddTargetDialogBase(parent, name, true) 00034 { 00035 m_subproject = item; 00036 m_widget = widget; 00037 // m_detailsView = view; 00038 00039 primary_combo->setFocus(); 00040 primary_combo->insertItem(i18n("Program")); 00041 primary_combo->insertItem(i18n("Library")); 00042 primary_combo->insertItem(i18n("Libtool Library")); 00043 primary_combo->insertItem(i18n("Script")); 00044 primary_combo->insertItem(i18n("Header")); 00045 primary_combo->insertItem(i18n("Data File")); 00046 primary_combo->insertItem(i18n("Java")); 00047 00048 primaryChanged(); // updates prefix combo 00049 00050 if (widget->kdeMode()) 00051 ldflagsother_edit->setText("$(all_libraries)"); 00052 00053 connect( filename_edit, SIGNAL( textChanged(const QString&) ), this, SLOT( slotFileNameChanged (const QString&) ) ); 00054 00055 setIcon ( SmallIcon ( "targetnew_kdevelop.png" ) ); 00056 00057 canonicalLabel->setText ( QString::null ); 00058 } 00059 00060 00061 AddTargetDialog::~AddTargetDialog() 00062 {} 00063 00064 00065 void AddTargetDialog::primaryChanged() 00066 { 00067 QStringList list; 00068 switch (primary_combo->currentItem()) { 00069 case 0: // Program 00070 list.append("bin"); 00071 list.append("sbin"); 00072 list.append("libexec"); 00073 list.append("pkglib"); 00074 list.append("noinst"); 00075 break; 00076 case 1: // Library 00077 case 2: // Libtool library 00078 list.append("lib"); 00079 list.append("pkglib"); 00080 list.append("noinst"); 00081 break; 00082 case 3: // Script 00083 list.append("bin"); 00084 list.append("sbin"); 00085 list.append("libexec"); 00086 list.append("pkgdata"); 00087 list.append("noinst"); 00088 break; 00089 case 4: // Header 00090 list.append("include"); 00091 list.append("oldinclude"); 00092 list.append("pkginclude"); 00093 list.append("noinst"); 00094 break; 00095 case 5: // Data 00096 list.append("bin"); 00097 list.append("sbin"); 00098 list.append("noinst"); 00099 break; 00100 case 6: // Java 00101 list.append("java"); 00102 list.append("noinst"); 00103 break; 00104 } 00105 00106 prefix_combo->clear(); 00107 00108 prefix_combo->insertStringList(list); 00109 QStringList prefixes; 00110 QMap<QString,QString>::ConstIterator it; 00111 for (it = m_subproject->prefixes.begin(); it != m_subproject->prefixes.end(); ++it) 00112 prefix_combo->insertItem(it.key()); 00113 00114 // Only enable ldflags stuff for libtool libraries 00115 bool lt = primary_combo->currentItem() == 2; 00116 bool prog = primary_combo->currentItem() == 0; 00117 allstatic_box->setEnabled(lt); 00118 avoidversion_box->setEnabled(lt); 00119 module_box->setEnabled(lt); 00120 noundefined_box->setEnabled(lt); 00121 ldflagsother_edit->setEnabled(lt || prog); 00122 } 00123 00124 00125 void AddTargetDialog::accept() 00126 { 00127 QString name = filename_edit->text().stripWhiteSpace(); 00128 QString prefix = prefix_combo->currentText(); 00129 00130 QString primary; 00131 switch (primary_combo->currentItem()) { 00132 case 0: primary = "PROGRAMS"; break; 00133 case 1: primary = "LIBRARIES"; break; 00134 case 2: primary = "LTLIBRARIES"; break; 00135 case 3: primary = "SCRIPTS"; break; 00136 case 4: primary = "HEADERS"; break; 00137 case 5: primary = "DATA"; break; 00138 case 6: primary = "JAVA"; break; 00139 default: ; 00140 } 00141 00142 if (primary == "DATA"){ 00143 // DATA does not need a name; DATA may already exist. 00144 TargetItem *titem = m_widget->createTargetItem(name, prefix, primary, true); 00145 QPtrListIterator<TargetItem> it( m_subproject->targets ); 00146 for( ; it.current(); ++it ){ 00147 if( (*it)->text(0) == titem->text(0) ){ 00150 QDialog::accept(); 00151 return; 00152 } 00153 } 00154 m_subproject->targets.append( titem ); 00155 QDialog::accept(); 00156 return; 00157 } 00158 00159 if (name.isEmpty()) { 00160 KMessageBox::sorry(this, i18n("You have to give the target a name!")); 00161 return; 00162 } 00163 00164 #if 0 00165 if (primary == "LIBRARIES" && !name.startsWith("lib")) { 00166 KMessageBox::sorry(this, i18n("Libraries must have a lib prefix!")); 00167 return; 00168 } 00169 00170 if (primary == "LTLIBRARIES" && !name.startsWith("lib")) { 00171 KMessageBox::sorry(this, i18n("Libtool libraries must have a lib prefix!")); 00172 return; 00173 } 00174 00175 if (primary == "LTLIBRARIES" && name.right(3) != ".la") { 00176 KMessageBox::sorry(this, i18n("Libtool libraries must have a .la suffix!")); 00177 return; 00178 } 00179 00180 #endif 00181 00182 if( primary.endsWith("LIBRARIES") && !name.startsWith("lib") ) 00183 name.prepend( QString::fromLatin1("lib") ); 00184 00185 if( primary == "LTLIBRARIES" && !name.endsWith(".la") ) 00186 name.append( QString::fromLatin1(".la") ); 00187 00188 if ( primary == "LIBRARIES" && !name.endsWith(".a") ) 00189 name.append ( QString::fromLatin1(".a") ); 00190 00191 QPtrListIterator<TargetItem> it(m_subproject->targets); 00192 for (; it.current(); ++it) 00193 if (name == (*it)->name) { 00194 KMessageBox::sorry(this, i18n("A target with this name already exists!")); 00195 return; 00196 } 00197 00198 QStringList flagslist; 00199 if (primary == "LTLIBRARIES") { 00200 if (allstatic_box->isChecked()) 00201 flagslist.append("-all-static"); 00202 if (avoidversion_box->isChecked()) 00203 flagslist.append("-avoid-version"); 00204 if (module_box->isChecked()) 00205 flagslist.append("-module"); 00206 if (noundefined_box->isChecked()) 00207 flagslist.append("-no-undefined"); 00208 } 00209 flagslist.append(ldflagsother_edit->text()); 00210 QString ldflags = flagslist.join( " " ); 00211 00212 TargetItem *titem = m_widget->createTargetItem(name, prefix, primary, false); 00213 // m_detailsView->insertItem ( titem ); 00214 m_subproject->targets.append(titem); 00215 00216 QString canonname = AutoProjectTool::canonicalize(name); 00217 00218 QMap<QString,QString> replaceMap; 00219 00220 if( primary == "PROGRAMS" || primary == "LIBRARIES" || primary == "LTLIBRARIES" ){ 00221 QString varname = prefix + "_" + primary; 00222 m_subproject->variables[varname] += (" " + name); 00223 replaceMap.insert(varname, m_subproject->variables[varname]); 00224 replaceMap.insert(canonname + "_SOURCES", ""); 00225 } 00226 if (primary == "LTLIBRARIES" || primary == "PROGRAMS") 00227 replaceMap.insert(canonname + "_LDFLAGS", ldflags); 00228 00229 AutoProjectTool::modifyMakefileam(m_subproject->path + "/Makefile.am", replaceMap); 00230 00231 QDialog::accept(); 00232 } 00233 00234 void AddTargetDialog::slotFileNameChanged ( const QString& text ) 00235 { 00236 canonicalLabel->setText ( AutoProjectTool::canonicalize ( text ) ); 00237 } 00238 00239 #include "addtargetdlg.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 Tue Oct 19 08:01:36 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003