1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
/***************************************************************************
-------------------
begin : 21.11.2002
copyright : (C) 2002 by Victor R�er
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "removetargetdlg.h"
#include <tqapplication.h>
#include <tqcheckbox.h>
#include <tqgroupbox.h>
#include <tqfile.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqpushbutton.h>
#include <tqregexp.h>
#include <kbuttonbox.h>
#include <kdebug.h>
#include <kdialog.h>
#include <klistbox.h>
#include <kprogress.h>
#include <ksqueezedtextlabel.h>
#include <klocale.h>
#include "autolistviewitems.h"
#include "misc.h"
#include "autoprojectpart.h"
#include "autoprojectwidget.h"
RemoveTargetDialog::RemoveTargetDialog( AutoProjectWidget *widget, AutoProjectPart* part, SubprojectItem *spitem,
TargetItem *titem, TQWidget* parent, const char* name )
: RemoveTargetDlgBase ( parent, name, true, 0 )
{
removeLabel->setText ( i18n ( "Do you really want to remove <b>%1</b><br>with <b>all files</b> that are attached to it<br>and <b>all dependencies</b>?" ).arg ( titem->name ) );
directoryLabel->setText ( spitem->path );
if ( titem->name.isEmpty() )
targetLabel->setText ( i18n ( "%1 in %2" ).arg ( titem->primary ).arg ( titem->prefix ) );
else
targetLabel->setText ( titem->name );
connect ( removeButton, TQT_SIGNAL ( clicked() ), this, TQT_SLOT ( accept() ) );
connect ( cancelButton, TQT_SIGNAL ( clicked() ), this, TQT_SLOT ( reject() ) );
setIcon ( SmallIcon ( "editdelete" ) );
progressBar->hide();
m_spitem = spitem;
m_titem = titem;
m_widget = widget;
m_part = part;
//kdDebug ( 9020 ) << "+++++ " << titem->primary << " " << titem->prefix << " " << titem->name << endl;
init();
}
RemoveTargetDialog::~RemoveTargetDialog()
{
}
void RemoveTargetDialog::init()
{
TQPtrList <SubprojectItem> subprojectItems = m_widget->allSubprojectItems();
TargetItem* titem = 0;
for ( SubprojectItem* spitem = subprojectItems.first(); spitem; spitem = subprojectItems.next() )
{
if ( m_titem->name.isEmpty() )
break;
for ( titem = spitem->targets.first(); titem; titem = spitem->targets.next() )
{
if ( m_titem->name == titem->name )
continue;
if ( titem->primary == "LTLIBRARIES" || titem->primary == "PROGRAMS"
|| titem->primary == "LIBRARIES" || titem->primary == "JAVA" )
{
TQString canonname = AutoProjectTool::canonicalize ( titem->name );
if ( spitem->variables[canonname + "_LIBADD"].contains ( m_titem->name ) > 0 ||
spitem->variables[canonname + "_LDADD"].contains ( m_titem->name ) > 0 )
{
dependencyListBox->insertItem ( SmallIcon ( "target_tdevelop" ), spitem->path + " (" + titem->name + ")" );
dependentSubprojects.append ( spitem );
}
}
}
}
if ( dependencyListBox->count() == 0 )
dependencyListBox->insertItem ( i18n("no dependency", "<none>") );
}
void RemoveTargetDialog::accept ()
{
progressBar->show();
progressBar->setFormat ( i18n ( "Removing Target... %p%" ) );
tqApp->processEvents();
TQString canonname = AutoProjectTool::canonicalize ( m_titem->name );
TQString varname = m_titem->prefix + "_" + m_titem->primary;
SubprojectItem* spitem = 0;
TargetItem* titem = 0;
TQMap <TQString, TQString> removeMap;
TQMap <TQString, TQString> replaceMap;
// Remove dependencies to other targets first (stored by init() in 'dependentTargets')
for ( spitem = dependentSubprojects.first(); spitem; spitem = dependentSubprojects.next() )
{
for ( titem = spitem->targets.first(); titem; titem = spitem->targets.next() )
{
TQString curVarname;
TQString curCanonname = AutoProjectTool::canonicalize ( titem->name );
TQStringList dependencies;
if ( spitem->variables[curCanonname + "_LIBADD"].contains ( m_titem->name ) )
curVarname = curCanonname + "_LIBADD";
else
curVarname = curCanonname + "_LDADD";
dependencies = TQStringList::split(TQRegExp("[ \t\n]"), spitem->variables[curVarname]);
//TQStringList::Iterator it = dependencies.begin();
for ( uint i = 0; i < dependencies.size(); ++i )
{
TQString s = dependencies[i];
if ( s.contains ( m_titem->name ) > 0 )
dependencies.remove ( s );
}
// if we removed the last entry of "blabla_LDADD" or "blabla_LIBADD", remove the complete line
if ( dependencies.count() == 0 )
{
removeMap.insert ( curVarname, "" );
AutoProjectTool::removeFromMakefileam ( spitem->path + "/Makefile.am", removeMap );
removeMap.clear();
}
else
{
spitem->variables[curVarname] = dependencies.join ( " " );
replaceMap.insert ( curVarname, spitem->variables[curVarname] );
AutoProjectTool::addToMakefileam ( spitem->path + "/Makefile.am", replaceMap );
replaceMap.clear();
}
}
}
// handling am_edit stuff
if ( m_titem->primary == "KDEICON" )
removeMap.insert ( "KDE_ICON", "" );
else if ( m_titem->primary == "KDEDOCS" )
removeMap.insert ( "KDE_DOCS", "" );
else
{
// if we have bin_PROGRAMS = [target to be deleted] [other target]
// delete only the [target to be deleted], not the whole line!
TQStringList targets = TQStringList::split(TQRegExp("[ \t\n]"), m_spitem->variables[varname]);
if ( targets.count() > 1 )
{
targets.remove ( m_titem->name );
m_spitem->variables[varname] = targets.join ( " " );
replaceMap.insert ( varname, m_spitem->variables[varname] );
AutoProjectTool::addToMakefileam ( m_spitem->path + "/Makefile.am", replaceMap );
replaceMap.clear();
}
else
{
removeMap.insert ( varname, m_titem->name );
}
}
// if we have no such line containing blabla_SOURCES, blabla_LDFLAGS, etc.
// they are ignored
removeMap.insert ( canonname + "_SOURCES", "" );
// remove from our internal list
m_spitem->variables.erase(canonname+"_SOURCES");
if ( m_titem->primary == "PROGRAMS" || m_titem->primary == "LTLIBRARIES" )
{
removeMap.insert ( canonname + "_LDFLAGS", "" );
removeMap.insert ( canonname + "_DEPENDENCIES", "" );
removeMap.insert ( canonname + "_LDADD", "" );
removeMap.insert ( canonname + "_LIBADD", "" );
}
AutoProjectTool::removeFromMakefileam ( m_spitem->path + "/Makefile.am", removeMap );
removeMap.clear();
// if we have another "blabla_PROGRAMS" or "blabla_LTLIBRARIES" target in the same subproject
// check if it has an empty "blabla_LIBADD"-entry
if ( m_titem->primary == "PROGRAMS" || m_titem->primary == "LTLIBRARIES" )
{
for ( titem = m_spitem->targets.first(); titem; titem = m_spitem->targets.next() )
{
//kdDebug (9020) << "******** " << m_spitem->subdir << endl;
if ( titem->primary == "PROGRAMS" || titem->primary == "LTLIBRARIES" )
{
TQString curCanonname = AutoProjectTool::canonicalize ( titem->name );
if ( m_spitem->variables[curCanonname + "_LIBADD"].isEmpty() )
{
removeMap.insert ( curCanonname + "_LIBADD", "" );
//kdDebug (9020) << "Removing from " << m_spitem->subdir << " " << curCanonname << "_LIBADD" << endl;
AutoProjectTool::removeFromMakefileam ( m_spitem->path + "/Makefile.am", removeMap );
removeMap.clear();
}
}
}
}
progressBar->setTotalSteps ( m_titem->sources.count() );
TQStringList fileList;
for ( FileItem* fitem = m_titem->sources.first(); fitem; fitem = m_titem->sources.next() )
{
if (removeCheckBox->isChecked())
{
// before removing the files, check if they are mentioned in "noinst_HEADERS = blabla1.h blabla2.h"
TQStringList noInstHeaders = TQStringList::split ( TQRegExp ( "[ \t\n]" ), m_spitem->variables["noinst_HEADERS"] );
if ( noInstHeaders.contains ( fitem->name ) )
{
noInstHeaders.remove ( fitem->name );
m_spitem->variables["noinst_HEADERS"] = noInstHeaders.join ( " " );
replaceMap.insert ( "noinst_HEADERS", m_spitem->variables["noinst_HEADERS"] );
AutoProjectTool::addToMakefileam ( m_spitem->path + "/Makefile.am", replaceMap );
replaceMap.clear();
}
TQFile::remove(m_spitem->path + "/" + fitem->name);
}
fileList.append ( m_spitem->path.mid ( m_part->projectDirectory().length() + 1 ) + "/" + fitem->name );
tqApp->processEvents();
progressBar->setValue ( progressBar->value() + 1 );
}
m_widget->emitRemovedFiles ( fileList );
m_spitem->targets.remove ( m_titem );
TQDialog::accept();
}
|