1
/***************************************************************************
2
* Copyright (C) 2001 by Bernd Gehrmann *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
***************************************************************************/
12
#include "addtargetdlg.h"
14
#include <qcheckbox.h>
15
#include <qcombobox.h>
16
#include <qgroupbox.h>
17
#include <qlineedit.h>
18
#include <qvalidator.h>
21
#include <kmessagebox.h>
22
#include <ksqueezedtextlabel.h>
24
#include "autolistviewitems.h"
27
#include "autodetailsview.h"
28
#include "autoprojectwidget.h"
31
AddTargetDialog::AddTargetDialog(AutoProjectWidget *widget, SubprojectItem *item,
32
QWidget *parent, const char *name)
33
: AddTargetDialogBase(parent, name, true)
37
// m_detailsView = view;
39
primary_combo->setFocus();
40
primary_combo->insertItem(i18n("Program"));
41
primary_combo->insertItem(i18n("Library"));
42
primary_combo->insertItem(i18n("Libtool Library"));
43
primary_combo->insertItem(i18n("Script"));
44
primary_combo->insertItem(i18n("Header"));
45
primary_combo->insertItem(i18n("Data File"));
46
primary_combo->insertItem(i18n("Java"));
48
primaryChanged(); // updates prefix combo
50
if (widget->kdeMode())
51
ldflagsother_edit->setText("$(all_libraries)");
53
connect( filename_edit, SIGNAL( textChanged(const QString&) ), this, SLOT( slotFileNameChanged (const QString&) ) );
55
setIcon ( SmallIcon ( "targetnew_kdevelop.png" ) );
57
canonicalLabel->setText ( QString::null );
61
AddTargetDialog::~AddTargetDialog()
65
void AddTargetDialog::primaryChanged()
68
switch (primary_combo->currentItem()) {
72
list.append("libexec");
73
list.append("pkglib");
74
list.append("noinst");
77
case 2: // Libtool library
79
list.append("pkglib");
80
list.append("noinst");
81
if (m_widget->kdeMode())
82
list.append("kde_module");
87
list.append("libexec");
88
list.append("pkgdata");
89
list.append("noinst");
92
list.append("include");
93
list.append("oldinclude");
94
list.append("pkginclude");
95
list.append("noinst");
100
list.append("noinst");
104
list.append("noinst");
108
prefix_combo->clear();
110
prefix_combo->insertStringList(list);
111
QStringList prefixes;
112
QMap<QString,QString>::ConstIterator it;
113
for (it = m_subproject->prefixes.begin(); it != m_subproject->prefixes.end(); ++it)
114
prefix_combo->insertItem(it.key());
116
// Only enable ldflags stuff for libtool libraries
117
bool lt = primary_combo->currentItem() == 2;
118
bool prog = primary_combo->currentItem() == 0;
119
allstatic_box->setEnabled(lt);
120
avoidversion_box->setEnabled(lt);
121
module_box->setEnabled(lt);
122
noundefined_box->setEnabled(lt);
123
ldflagsother_edit->setEnabled(lt || prog);
127
void AddTargetDialog::accept()
129
QString name = filename_edit->text().stripWhiteSpace();
130
QString prefix = prefix_combo->currentText();
133
switch (primary_combo->currentItem()) {
134
case 0: primary = "PROGRAMS"; break;
135
case 1: primary = "LIBRARIES"; break;
136
case 2: primary = "LTLIBRARIES"; break;
137
case 3: primary = "SCRIPTS"; break;
138
case 4: primary = "HEADERS"; break;
139
case 5: primary = "DATA"; break;
140
case 6: primary = "JAVA"; break;
144
if (primary == "DATA"){
145
// DATA does not need a name; DATA may already exist.
146
TargetItem *titem = m_widget->createTargetItem(name, prefix, primary, true);
147
QPtrListIterator<TargetItem> it( m_subproject->targets );
148
for( ; it.current(); ++it ){
149
if( (*it)->text(0) == titem->text(0) ){
150
/// \FIXME Add message box here, after string-freeze is over
151
/// something like: "This data target already exists."
156
m_subproject->targets.append( titem );
161
if (name.isEmpty()) {
162
KMessageBox::sorry(this, i18n("You have to give the target a name"));
167
if (primary == "LIBRARIES" && !name.startsWith("lib")) {
168
KMessageBox::sorry(this, i18n("Libraries must have a lib prefix."));
172
if (primary == "LTLIBRARIES" && !name.startsWith("lib")) {
173
KMessageBox::sorry(this, i18n("Libtool libraries must have a lib prefix."));
177
if (primary == "LTLIBRARIES" && name.right(3) != ".la") {
178
KMessageBox::sorry(this, i18n("Libtool libraries must have a .la suffix."));
184
if( primary.endsWith("LIBRARIES") && !name.startsWith("lib") )
185
name.prepend( QString::fromLatin1("lib") );
187
if( primary == "LTLIBRARIES" && !name.endsWith(".la") )
188
name.append( QString::fromLatin1(".la") );
190
if ( primary == "LIBRARIES" && !name.endsWith(".a") )
191
name.append ( QString::fromLatin1(".a") );
193
QPtrListIterator<TargetItem> it(m_subproject->targets);
194
for (; it.current(); ++it)
195
if (name == (*it)->name) {
196
KMessageBox::sorry(this, i18n("A target with this name already exists."));
200
QStringList flagslist;
201
if (primary == "LTLIBRARIES") {
202
if (allstatic_box->isChecked())
203
flagslist.append("-all-static");
204
if (avoidversion_box->isChecked())
205
flagslist.append("-avoid-version");
206
if (module_box->isChecked())
207
flagslist.append("-module");
208
if (noundefined_box->isChecked())
209
flagslist.append("-no-undefined");
211
flagslist.append(ldflagsother_edit->text());
212
QString ldflags = flagslist.join( " " );
214
TargetItem *titem = m_widget->createTargetItem(name, prefix, primary, false);
215
// m_detailsView->insertItem ( titem );
216
m_subproject->targets.append(titem);
218
QString canonname = AutoProjectTool::canonicalize(name);
220
QMap<QString,QString> replaceMap;
222
if( primary == "PROGRAMS" || primary == "LIBRARIES" || primary == "LTLIBRARIES" ){
223
QString varname = prefix + "_" + primary;
224
m_subproject->variables[varname] += (" " + name);
225
replaceMap.insert(varname, m_subproject->variables[varname]);
226
replaceMap.insert(canonname + "_SOURCES", "");
228
if (primary == "LTLIBRARIES" || primary == "PROGRAMS")
229
replaceMap.insert(canonname + "_LDFLAGS", ldflags);
231
AutoProjectTool::modifyMakefileam(m_subproject->path + "/Makefile.am", replaceMap);
236
void AddTargetDialog::slotFileNameChanged ( const QString& text )
238
canonicalLabel->setText ( AutoProjectTool::canonicalize ( text ) );
241
#include "addtargetdlg.moc"