~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to buildtools/autotools/addtargetdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2001 by Bernd Gehrmann                                  *
 
3
 *   bernd@kdevelop.org                                                    *
 
4
 *                                                                         *
 
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.                                   *
 
9
 *                                                                         *
 
10
 ***************************************************************************/
 
11
 
 
12
#include "addtargetdlg.h"
 
13
 
 
14
#include <qcheckbox.h>
 
15
#include <qcombobox.h>
 
16
#include <qgroupbox.h>
 
17
#include <qlineedit.h>
 
18
#include <qvalidator.h>
 
19
 
 
20
#include <klocale.h>
 
21
#include <kmessagebox.h>
 
22
#include <ksqueezedtextlabel.h>
 
23
 
 
24
#include "autolistviewitems.h"
 
25
 
 
26
#include "misc.h"
 
27
#include "autodetailsview.h"
 
28
#include "autoprojectwidget.h"
 
29
 
 
30
 
 
31
AddTargetDialog::AddTargetDialog(AutoProjectWidget *widget, SubprojectItem *item,
 
32
                                                                QWidget *parent, const char *name)
 
33
        : AddTargetDialogBase(parent, name, true)
 
34
{
 
35
        m_subproject = item;
 
36
        m_widget = widget;
 
37
//      m_detailsView = view;
 
38
 
 
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"));
 
47
 
 
48
        primaryChanged(); // updates prefix combo
 
49
 
 
50
        if (widget->kdeMode())
 
51
                ldflagsother_edit->setText("$(all_libraries)");
 
52
 
 
53
        connect( filename_edit, SIGNAL( textChanged(const QString&) ), this, SLOT( slotFileNameChanged (const QString&) ) );
 
54
 
 
55
        setIcon ( SmallIcon ( "targetnew_kdevelop.png" ) );
 
56
 
 
57
        canonicalLabel->setText ( QString::null );
 
58
}
 
59
 
 
60
 
 
61
AddTargetDialog::~AddTargetDialog()
 
62
{}
 
63
 
 
64
 
 
65
void AddTargetDialog::primaryChanged()
 
66
{
 
67
        QStringList list;
 
68
        switch (primary_combo->currentItem()) {
 
69
        case 0: // Program
 
70
                list.append("bin");
 
71
                list.append("sbin");
 
72
                list.append("libexec");
 
73
                list.append("pkglib");
 
74
                list.append("noinst");
 
75
                break;
 
76
        case 1: // Library
 
77
        case 2: // Libtool library
 
78
                list.append("lib");
 
79
                list.append("pkglib");
 
80
                list.append("noinst");
 
81
                if (m_widget->kdeMode())
 
82
                        list.append("kde_module");
 
83
                break;
 
84
        case 3: // Script
 
85
                list.append("bin");
 
86
                list.append("sbin");
 
87
                list.append("libexec");
 
88
                list.append("pkgdata");
 
89
                list.append("noinst");
 
90
                break;
 
91
        case 4: // Header
 
92
                list.append("include");
 
93
                list.append("oldinclude");
 
94
                list.append("pkginclude");
 
95
                list.append("noinst");
 
96
                break;
 
97
        case 5: // Data
 
98
                list.append("bin");
 
99
                list.append("sbin");
 
100
                list.append("noinst");
 
101
                break;
 
102
        case 6: // Java
 
103
                list.append("java");
 
104
                list.append("noinst");
 
105
                break;
 
106
        }
 
107
 
 
108
        prefix_combo->clear();
 
109
 
 
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());
 
115
 
 
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);
 
124
}
 
125
 
 
126
 
 
127
void AddTargetDialog::accept()
 
128
{
 
129
        QString name = filename_edit->text().stripWhiteSpace();
 
130
        QString prefix = prefix_combo->currentText();
 
131
 
 
132
        QString primary;
 
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;
 
141
        default: ;
 
142
        }
 
143
 
 
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."
 
152
                    QDialog::accept();
 
153
                    return;
 
154
                }
 
155
            }
 
156
            m_subproject->targets.append( titem );
 
157
            QDialog::accept();
 
158
            return;
 
159
        }
 
160
 
 
161
        if (name.isEmpty()) {
 
162
                KMessageBox::sorry(this, i18n("You have to give the target a name"));
 
163
                return;
 
164
        }
 
165
 
 
166
#if 0
 
167
        if (primary == "LIBRARIES" && !name.startsWith("lib")) {
 
168
                KMessageBox::sorry(this, i18n("Libraries must have a lib prefix."));
 
169
                return;
 
170
        }
 
171
 
 
172
        if (primary == "LTLIBRARIES" && !name.startsWith("lib")) {
 
173
                KMessageBox::sorry(this, i18n("Libtool libraries must have a lib prefix."));
 
174
                return;
 
175
        }
 
176
 
 
177
        if (primary == "LTLIBRARIES" && name.right(3) != ".la") {
 
178
                KMessageBox::sorry(this, i18n("Libtool libraries must have a .la suffix."));
 
179
                return;
 
180
        }
 
181
 
 
182
#endif
 
183
 
 
184
        if( primary.endsWith("LIBRARIES") && !name.startsWith("lib") )
 
185
            name.prepend( QString::fromLatin1("lib") );
 
186
 
 
187
        if( primary == "LTLIBRARIES" && !name.endsWith(".la") )
 
188
            name.append( QString::fromLatin1(".la") );
 
189
 
 
190
        if ( primary == "LIBRARIES" && !name.endsWith(".a") )
 
191
            name.append ( QString::fromLatin1(".a") );
 
192
 
 
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."));
 
197
                        return;
 
198
                }
 
199
 
 
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");
 
210
        }
 
211
        flagslist.append(ldflagsother_edit->text());
 
212
        QString ldflags = flagslist.join( " " );
 
213
 
 
214
        TargetItem *titem = m_widget->createTargetItem(name, prefix, primary, false);
 
215
        // m_detailsView->insertItem ( titem );
 
216
        m_subproject->targets.append(titem);
 
217
 
 
218
        QString canonname = AutoProjectTool::canonicalize(name);
 
219
 
 
220
        QMap<QString,QString> replaceMap;
 
221
 
 
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", "");
 
227
        }
 
228
        if (primary == "LTLIBRARIES" || primary == "PROGRAMS")
 
229
            replaceMap.insert(canonname + "_LDFLAGS", ldflags);
 
230
 
 
231
        AutoProjectTool::modifyMakefileam(m_subproject->path + "/Makefile.am", replaceMap);
 
232
 
 
233
        QDialog::accept();
 
234
}
 
235
 
 
236
void AddTargetDialog::slotFileNameChanged ( const QString& text )
 
237
{
 
238
        canonicalLabel->setText ( AutoProjectTool::canonicalize ( text ) );
 
239
}
 
240
 
 
241
#include "addtargetdlg.moc"