KDevelop API Documentation

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         if (m_widget->kdeMode())
00082             list.append("kde_module");
00083         break;
00084     case 3: // Script
00085         list.append("bin");
00086         list.append("sbin");
00087         list.append("libexec");
00088         list.append("pkgdata");
00089         list.append("noinst");
00090         break;
00091     case 4: // Header
00092         list.append("include");
00093         list.append("oldinclude");
00094         list.append("pkginclude");
00095         list.append("noinst");
00096         break;
00097     case 5: // Data
00098         list.append("bin");
00099         list.append("sbin");
00100         list.append("noinst");
00101         break;
00102     case 6: // Java
00103         list.append("java");
00104         list.append("noinst");
00105         break;
00106     }
00107 
00108     prefix_combo->clear();
00109 
00110     prefix_combo->insertStringList(list);
00111     QStringList prefixes;
00112     QMap<QString,QString>::ConstIterator it;
00113     for (it = m_subproject->prefixes.begin(); it != m_subproject->prefixes.end(); ++it)
00114         prefix_combo->insertItem(it.key());
00115 
00116     // Only enable ldflags stuff for libtool libraries
00117     bool lt = primary_combo->currentItem() == 2;
00118     bool prog = primary_combo->currentItem() == 0;
00119     allstatic_box->setEnabled(lt);
00120     avoidversion_box->setEnabled(lt);
00121     module_box->setEnabled(lt);
00122     noundefined_box->setEnabled(lt);
00123     ldflagsother_edit->setEnabled(lt || prog);
00124 }
00125 
00126 
00127 void AddTargetDialog::accept()
00128 {
00129     QString name = filename_edit->text().stripWhiteSpace();
00130     QString prefix = prefix_combo->currentText();
00131 
00132     QString primary;
00133     switch (primary_combo->currentItem()) {
00134     case 0: primary = "PROGRAMS";    break;
00135     case 1: primary = "LIBRARIES";   break;
00136     case 2: primary = "LTLIBRARIES"; break;
00137     case 3: primary = "SCRIPTS";     break;
00138     case 4: primary = "HEADERS";     break;
00139     case 5: primary = "DATA";        break;
00140     case 6: primary = "JAVA";        break;
00141     default: ;
00142     }
00143 
00144     if (primary == "DATA"){
00145         // DATA does not need a name; DATA may already exist.
00146         TargetItem *titem = m_widget->createTargetItem(name, prefix, primary, true);
00147         QPtrListIterator<TargetItem> it( m_subproject->targets );
00148         for( ; it.current(); ++it ){
00149         if( (*it)->text(0) == titem->text(0) ){
00152             QDialog::accept();
00153             return;
00154         }
00155         }
00156         m_subproject->targets.append( titem );
00157         QDialog::accept();
00158         return;
00159     }
00160 
00161     if (name.isEmpty()) {
00162         KMessageBox::sorry(this, i18n("You have to give the target a name"));
00163         return;
00164     }
00165 
00166 #if 0
00167     if (primary == "LIBRARIES" && !name.startsWith("lib")) {
00168         KMessageBox::sorry(this, i18n("Libraries must have a lib prefix."));
00169         return;
00170     }
00171 
00172     if (primary == "LTLIBRARIES" && !name.startsWith("lib")) {
00173         KMessageBox::sorry(this, i18n("Libtool libraries must have a lib prefix."));
00174         return;
00175     }
00176 
00177     if (primary == "LTLIBRARIES" && name.right(3) != ".la") {
00178         KMessageBox::sorry(this, i18n("Libtool libraries must have a .la suffix."));
00179         return;
00180     }
00181 
00182 #endif
00183 
00184     if( primary.endsWith("LIBRARIES") && !name.startsWith("lib") )
00185         name.prepend( QString::fromLatin1("lib") );
00186 
00187     if( primary == "LTLIBRARIES" && !name.endsWith(".la") )
00188         name.append( QString::fromLatin1(".la") );
00189 
00190     if ( primary == "LIBRARIES" && !name.endsWith(".a") )
00191         name.append ( QString::fromLatin1(".a") );
00192 
00193     QPtrListIterator<TargetItem> it(m_subproject->targets);
00194     for (; it.current(); ++it)
00195         if (name == (*it)->name) {
00196             KMessageBox::sorry(this, i18n("A target with this name already exists."));
00197             return;
00198         }
00199 
00200     QStringList flagslist;
00201     if (primary == "LTLIBRARIES") {
00202         if (allstatic_box->isChecked())
00203             flagslist.append("-all-static");
00204         if (avoidversion_box->isChecked())
00205             flagslist.append("-avoid-version");
00206         if (module_box->isChecked())
00207             flagslist.append("-module");
00208         if (noundefined_box->isChecked())
00209             flagslist.append("-no-undefined");
00210     }
00211     flagslist.append(ldflagsother_edit->text());
00212     QString ldflags = flagslist.join( " " );
00213 
00214     TargetItem *titem = m_widget->createTargetItem(name, prefix, primary, false);
00215     // m_detailsView->insertItem ( titem );
00216     m_subproject->targets.append(titem);
00217 
00218     QString canonname = AutoProjectTool::canonicalize(name);
00219 
00220     QMap<QString,QString> replaceMap;
00221 
00222         if( primary == "PROGRAMS" || primary == "LIBRARIES" || primary == "LTLIBRARIES" ){
00223         QString varname = prefix + "_" + primary;
00224         m_subproject->variables[varname] += (" " + name);
00225         replaceMap.insert(varname, m_subproject->variables[varname]);
00226             replaceMap.insert(canonname + "_SOURCES", "");
00227         }
00228     if (primary == "LTLIBRARIES" || primary == "PROGRAMS")
00229             replaceMap.insert(canonname + "_LDFLAGS", ldflags);
00230 
00231     AutoProjectTool::modifyMakefileam(m_subproject->path + "/Makefile.am", replaceMap);
00232 
00233     QDialog::accept();
00234 }
00235 
00236 void AddTargetDialog::slotFileNameChanged ( const QString& text )
00237 {
00238     canonicalLabel->setText ( AutoProjectTool::canonicalize ( text ) );
00239 }
00240 
00241 #include "addtargetdlg.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:21 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003