~ubuntu-branches/ubuntu/karmic/kdevelop/karmic

« back to all changes in this revision

Viewing changes to buildtools/autotools/targetoptionsdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2009-05-25 19:34:26 UTC
  • mfrom: (1.1.11 upstream) (2.3.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090525193426-hdntv90rvflyew8g
Tags: 4:3.9.93-1ubuntu1
* Merge from Debian experimental, remaining changes:
  - Conflict/replace -kde4 packages

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 "targetoptionsdlg.h"
13
 
 
14
 
#include <qcheckbox.h>
15
 
#include <qheader.h>
16
 
#include <qlabel.h>
17
 
#include <qlayout.h>
18
 
#include <qregexp.h>
19
 
#include <klineedit.h>
20
 
#include <kbuttonbox.h>
21
 
#include <kdialog.h>
22
 
#include <kinputdialog.h>
23
 
#include <kurlrequesterdlg.h>
24
 
#include <kurlrequester.h>
25
 
#include <kurlcompletion.h>
26
 
#include <klocale.h>
27
 
#include <knotifyclient.h>
28
 
#include <kfiledialog.h>
29
 
#include "autolistviewitems.h"
30
 
 
31
 
#include "misc.h"
32
 
#include "autoprojectpart.h"
33
 
#include "autoprojectwidget.h"
34
 
#include "urlutil.h"
35
 
 
36
 
TargetOptionsDialog::TargetOptionsDialog(AutoProjectWidget *widget, TargetItem *item,
37
 
                                         QWidget *parent, const char *name)
38
 
    : TargetOptionsDialogBase(parent, name, true)
39
 
{
40
 
    setCaption( i18n("Target Options for '%1'").arg(item->name) );
41
 
    setIcon( SmallIcon("configure") );
42
 
 
43
 
    target = item;
44
 
    m_widget = widget;
45
 
 
46
 
    if (item->primary == "PROGRAMS") {
47
 
        insidelib_label->setText(i18n("Link convenience libraries inside project (LDADD)"));
48
 
        outsidelib_label->setText(i18n("Link libraries outside project (LDADD)"));
49
 
    }
50
 
    else
51
 
        argumentBox->setEnabled( false );
52
 
//         run_arguments_edit->setEnabled(false);
53
 
 
54
 
    insidelib_listview->header()->hide();
55
 
    outsidelib_listview->header()->hide();
56
 
    insidelib_listview->setSorting(-1);
57
 
    outsidelib_listview->setSorting(-1);
58
 
 
59
 
 
60
 
    m_cwdEdit->completionObject()->setMode(KURLCompletion::DirCompletion);
61
 
    m_cwdEdit->setMode( KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly );
62
 
 
63
 
    // Insert all convenience libraries as possible linked libraries
64
 
    QStringList l = widget->allLibraries();
65
 
    QStringList::ConstIterator it;
66
 
    QString fulltargetname = m_widget->subprojectDirectory() + "/" + item->name;
67
 
    for (it = l.begin(); it != l.end(); ++it)
68
 
        // Do not list the target itself (a target can not link with itself)
69
 
        if ( !fulltargetname.endsWith(*it) )
70
 
            (void) new QCheckListItem(insidelib_listview, *it, QCheckListItem::CheckBox);
71
 
    readConfig();
72
 
}
73
 
 
74
 
 
75
 
TargetOptionsDialog::~TargetOptionsDialog()
76
 
{}
77
 
 
78
 
 
79
 
void TargetOptionsDialog::readConfig()
80
 
{
81
 
    QString flagsstr = target->ldflags;
82
 
    flagsstr.replace(QRegExp("$(KDE_PLUGIN)"), "-avoid-version -module -no-undefined $(KDE_RPATH)");
83
 
    QStringList l1 = QStringList::split(QRegExp("[ \t]"), flagsstr);
84
 
    QStringList::Iterator l1it;
85
 
 
86
 
    l1it = l1.find("-all-static");
87
 
    if (l1it != l1.end()) {
88
 
        allstatic_box->setChecked(true);
89
 
        l1.remove(l1it);
90
 
    }
91
 
    l1it = l1.find("-avoid-version");
92
 
    if (l1it != l1.end()) {
93
 
        avoidversion_box->setChecked(true);
94
 
        l1.remove(l1it);
95
 
    }
96
 
    l1it = l1.find("-module");
97
 
    if (l1it != l1.end()) {
98
 
        module_box->setChecked(true);
99
 
        l1.remove(l1it);
100
 
    }
101
 
    l1it = l1.find("-no-undefined");
102
 
    if (l1it != l1.end()) {
103
 
        noundefined_box->setChecked(true);
104
 
        l1.remove(l1it);
105
 
    }
106
 
    ldflagsother_edit->setText(l1.join(" "));
107
 
    dependencies_edit->setText(target->dependencies);
108
 
 
109
 
    QString addstr = (target->primary == "PROGRAMS")? target->ldadd : target->libadd;
110
 
    QStringList l2 = QStringList::split(QRegExp("[ \t]"), addstr);
111
 
 
112
 
    kdDebug(9020) << "ls=: " << addstr << endl;
113
 
 
114
 
    bool inlistItem;
115
 
    QListViewItem *lastItem = 0;
116
 
    QStringList::Iterator l2it;
117
 
    QCheckListItem *flitem = static_cast<QCheckListItem*>(insidelib_listview->firstChild());
118
 
    for (l2it = l2.begin(); l2it != l2.end(); ++l2it) {
119
 
        inlistItem = false;
120
 
        QCheckListItem *clitem = static_cast<QCheckListItem*>(insidelib_listview->firstChild());
121
 
        if (flitem) {
122
 
            while (clitem) {
123
 
                if (*l2it == ("$(top_builddir)/" + clitem->text())) {
124
 
                    clitem->setOn(true);
125
 
                    // move this item to the "top of the list"
126
 
                    if (flitem != clitem)
127
 
                      clitem->moveItem(flitem);
128
 
                    // move the "top of the list" one item down
129
 
                    flitem = static_cast<QCheckListItem*>(flitem->nextSibling());
130
 
                    inlistItem = true;
131
 
                    break;
132
 
                }
133
 
                clitem = static_cast<QCheckListItem*>(clitem->nextSibling());
134
 
            }
135
 
        }
136
 
        if ( inlistItem == false ) {
137
 
            QListViewItem *item = new QListViewItem(outsidelib_listview, *l2it);
138
 
            if (lastItem)
139
 
                item->moveItem(lastItem);
140
 
            lastItem = item;
141
 
        }
142
 
    }
143
 
 
144
 
    if (target->primary == "PROGRAMS")
145
 
    {
146
 
        run_arguments_edit->setText(DomUtil::readEntry(*m_widget->m_part->projectDom(), "/kdevautoproject/run/runarguments/" + target->name));
147
 
        if( DomUtil::readEntry(*m_widget->m_part->projectDom(), "/kdevautoproject/run/cwd/" + target->name).isEmpty() )
148
 
        {
149
 
            m_cwdEdit->setURL( m_widget->m_part->buildDirectory()+"/"+URLUtil::getRelativePath(m_widget->m_part->topsourceDirectory(), m_widget->m_part->projectDirectory())+"/"+m_widget->activeDirectory() );
150
 
            m_cwdEdit->fileDialog()->setURL( KURL::fromPathOrURL( m_widget->m_part->buildDirectory()+"/"+URLUtil::getRelativePath(m_widget->m_part->topsourceDirectory(), m_widget->m_part->projectDirectory())+"/"+m_widget->activeDirectory() ) );
151
 
        }else
152
 
        {
153
 
            m_cwdEdit->setURL( DomUtil::readEntry(*m_widget->m_part->projectDom(), "/kdevautoproject/run/cwd/" + target->name) );
154
 
            m_cwdEdit->fileDialog()->setURL( KURL::fromPathOrURL( DomUtil::readEntry(*m_widget->m_part->projectDom(), "/kdevautoproject/run/cwd/" + target->name) ) );
155
 
        }
156
 
        debug_arguments_edit->setText(DomUtil::readEntry(*m_widget->m_part->projectDom(), "/kdevautoproject/run/debugarguments/" + target->name));
157
 
    }
158
 
}
159
 
 
160
 
 
161
 
void TargetOptionsDialog::storeConfig()
162
 
{
163
 
    QStringList flagslist;
164
 
    if (allstatic_box->isChecked())
165
 
        flagslist.append("-all-static");
166
 
    if (avoidversion_box->isChecked())
167
 
        flagslist.append("-avoid-version");
168
 
    if (module_box->isChecked())
169
 
        flagslist.append("-module");
170
 
    if (noundefined_box->isChecked())
171
 
        flagslist.append("-no-undefined");
172
 
    flagslist.append(ldflagsother_edit->text());
173
 
    QString new_ldflags = flagslist.join(" ");
174
 
 
175
 
    QStringList liblist;
176
 
    QCheckListItem *clitem = static_cast<QCheckListItem*>(insidelib_listview->firstChild());
177
 
    while (clitem) {
178
 
        if( clitem->isOn() )
179
 
            liblist.append("$(top_builddir)/" + clitem->text());
180
 
        clitem = static_cast<QCheckListItem*>(clitem->nextSibling());
181
 
    }
182
 
    clitem = static_cast<QCheckListItem*>(outsidelib_listview->firstChild());
183
 
    while (clitem) {
184
 
        liblist.append(clitem->text());
185
 
        clitem = static_cast<QCheckListItem*>(clitem->nextSibling());
186
 
    }
187
 
    QString new_addstr = liblist.join(" ");
188
 
 
189
 
    QString canonname = AutoProjectTool::canonicalize(target->name);
190
 
    QMap<QString, QString> replaceMap;
191
 
 
192
 
    if (target->primary == "PROGRAMS") {
193
 
        QString old_ldadd = target->ldadd;
194
 
        if (new_addstr != old_ldadd) {
195
 
            target->ldadd = new_addstr;
196
 
            replaceMap.insert(canonname + "_LDADD", new_addstr);
197
 
        }
198
 
    }
199
 
 
200
 
    if (target->primary == "LIBRARIES" || target->primary == "LTLIBRARIES") {
201
 
        QString old_libadd = target->libadd;
202
 
        if (new_addstr != old_libadd) {
203
 
            target->libadd = new_addstr;
204
 
            replaceMap.insert(canonname + "_LIBADD", new_addstr);
205
 
        }
206
 
    }
207
 
 
208
 
    QString old_ldflags = target->ldflags;
209
 
    if (new_ldflags != old_ldflags) {
210
 
        target->ldflags = new_ldflags;
211
 
        replaceMap.insert(canonname + "_LDFLAGS", new_ldflags);
212
 
    }
213
 
 
214
 
    QString new_dependencies = dependencies_edit->text();
215
 
    QString old_dependencies = target->dependencies;
216
 
    if (new_dependencies != old_dependencies) {
217
 
        target->dependencies = new_dependencies;
218
 
        if (!new_dependencies.isEmpty())
219
 
            replaceMap.insert(canonname + "_DEPENDENCIES", new_dependencies);
220
 
    }
221
 
 
222
 
    // We can safely assume that this target is in the active sub project
223
 
    AutoProjectTool::setMakefileam(m_widget->subprojectDirectory() + "/Makefile.am", replaceMap);
224
 
 
225
 
    if (target->primary == "PROGRAMS")
226
 
    {
227
 
        DomUtil::writeEntry(*m_widget->m_part->projectDom(), "/kdevautoproject/run/runarguments/" + target->name, run_arguments_edit->text());
228
 
        DomUtil::writeEntry(*m_widget->m_part->projectDom(), "/kdevautoproject/run/debugarguments/" + target->name, debug_arguments_edit->text());
229
 
        DomUtil::writeEntry(*m_widget->m_part->projectDom(), "/kdevautoproject/run/cwd/" + target->name, m_cwdEdit->url());
230
 
    }
231
 
}
232
 
 
233
 
 
234
 
void TargetOptionsDialog::insideMoveUpClicked()
235
 
{
236
 
    if (!insidelib_listview->currentItem())
237
 
        return;
238
 
    if (insidelib_listview->currentItem() == insidelib_listview->firstChild()) {
239
 
        KNotifyClient::beep();
240
 
        return;
241
 
    }
242
 
 
243
 
    QListViewItem *item = insidelib_listview->firstChild();
244
 
    while (item->nextSibling() != insidelib_listview->currentItem())
245
 
        item = item->nextSibling();
246
 
    item->moveItem(insidelib_listview->currentItem());
247
 
}
248
 
 
249
 
 
250
 
void TargetOptionsDialog::insideMoveDownClicked()
251
 
{
252
 
   if (!insidelib_listview->currentItem())
253
 
       return;
254
 
 
255
 
   if (insidelib_listview->currentItem()->nextSibling() == 0) {
256
 
        KNotifyClient::beep();
257
 
        return;
258
 
   }
259
 
 
260
 
   insidelib_listview->currentItem()->moveItem(insidelib_listview->currentItem()->nextSibling());
261
 
}
262
 
 
263
 
 
264
 
void TargetOptionsDialog::outsideMoveUpClicked()
265
 
{
266
 
    if (!outsidelib_listview->currentItem())
267
 
        return;
268
 
    if (outsidelib_listview->currentItem() == outsidelib_listview->firstChild()) {
269
 
        KNotifyClient::beep();
270
 
        return;
271
 
    }
272
 
 
273
 
    QListViewItem *item = outsidelib_listview->firstChild();
274
 
    while (item->nextSibling() != outsidelib_listview->currentItem())
275
 
        item = item->nextSibling();
276
 
    item->moveItem(outsidelib_listview->currentItem());
277
 
}
278
 
 
279
 
 
280
 
void TargetOptionsDialog::outsideMoveDownClicked()
281
 
{
282
 
   if (!outsidelib_listview->currentItem())
283
 
       return;
284
 
   if (outsidelib_listview->currentItem()->nextSibling() == 0) {
285
 
        KNotifyClient::beep();
286
 
        return;
287
 
   }
288
 
 
289
 
   outsidelib_listview->currentItem()->moveItem(outsidelib_listview->currentItem()->nextSibling());
290
 
}
291
 
 
292
 
 
293
 
void TargetOptionsDialog::outsideAddClicked()
294
 
{
295
 
    KURLRequesterDlg dialog( "", i18n( "Add Library: Choose the .a/.so file, give -l<libname> or use a variable with $(FOOBAR)" ), 0, 0 );
296
 
    dialog.urlRequester() ->setMode( KFile::File | KFile::ExistingOnly | KFile::LocalOnly );
297
 
    dialog.urlRequester() ->setFilter( "*.so|"+i18n("Shared Library (*.so)")+"\n*.a|"+i18n("Static Library (*.a)") );
298
 
    dialog.urlRequester() ->setURL( QString::null );
299
 
    dialog.urlRequester() ->completionObject() ->setDir( m_widget->selectedSubproject()->path );
300
 
    dialog.urlRequester() ->fileDialog() ->setURL( KURL::fromPathOrURL( m_widget->selectedSubproject()->path ) );
301
 
    if ( dialog.exec() != QDialog::Accepted )
302
 
        return ;
303
 
    QString file = dialog.urlRequester() ->url();
304
 
    if ( !file.isEmpty() )
305
 
    {
306
 
        if ( !file.isEmpty() )
307
 
        {
308
 
            if( file.startsWith("-l") )
309
 
                new QListViewItem( outsidelib_listview, file );
310
 
            else
311
 
            {
312
 
                QFileInfo fi(file);
313
 
                if( !fi.exists() )
314
 
                    new QListViewItem( outsidelib_listview, file );
315
 
                if( fi.extension(false) == "a" )
316
 
                {
317
 
                    new QListViewItem( outsidelib_listview, file );
318
 
                }else if ( fi.extension(false) == "so" )
319
 
                {
320
 
                    QString name = fi.fileName();
321
 
                    if( name.startsWith( "lib" ) )
322
 
                        name = name.mid(3);
323
 
                    name = "-l"+name.left( name.length() - 3 );
324
 
                    new QListViewItem( outsidelib_listview, name );
325
 
                }
326
 
            }
327
 
        }
328
 
    }
329
 
}
330
 
 
331
 
 
332
 
void TargetOptionsDialog::outsideEditClicked()
333
 
{
334
 
    if ( (outsidelib_listview->childCount()==0) || (outsidelib_listview->currentItem() == 0) )
335
 
        return;
336
 
    bool ok;
337
 
    QString dir = KInputDialog::getText(i18n("Edit External Library"), i18n("Edit external library:"),
338
 
            outsidelib_listview->currentItem()-> text(0), &ok, 0);
339
 
    if (ok && !dir.isEmpty())
340
 
        outsidelib_listview->currentItem()-> setText(0, dir);
341
 
}
342
 
 
343
 
 
344
 
void TargetOptionsDialog::outsideRemoveClicked()
345
 
{
346
 
    delete outsidelib_listview->currentItem();
347
 
}
348
 
 
349
 
 
350
 
void TargetOptionsDialog::accept()
351
 
{
352
 
    storeConfig();
353
 
    QDialog::accept();
354
 
}
355
 
 
356
 
#include "targetoptionsdlg.moc"
357
 
// kate: indent-mode csands; space-indent on; indent-width 4; replace-tabs on;