00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
#include "removetargetdlg.h"
00018
00019
#include <qapplication.h>
00020
#include <qcheckbox.h>
00021
#include <qgroupbox.h>
00022
#include <qfile.h>
00023
#include <qlabel.h>
00024
#include <qlayout.h>
00025
#include <qpushbutton.h>
00026
#include <qregexp.h>
00027
00028
#include <kbuttonbox.h>
00029
#include <kdebug.h>
00030
#include <kdialog.h>
00031
#include <klistbox.h>
00032
#include <kprogress.h>
00033
#include <ksqueezedtextlabel.h>
00034
#include <klocale.h>
00035
00036
#include "autolistviewitems.h"
00037
00038
#include "misc.h"
00039
00040
#include "autoprojectpart.h"
00041
#include "autoprojectwidget.h"
00042
00043
00044 RemoveTargetDialog::RemoveTargetDialog(
AutoProjectWidget *widget,
AutoProjectPart* part,
SubprojectItem *spitem,
00045
TargetItem *titem,
QWidget* parent,
const char* name )
00046 :
RemoveTargetDlgBase ( parent, name, true, 0 )
00047 {
00048 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 ) );
00049 directoryLabel->
setText ( spitem->
path );
00050
00051
if ( titem->
name.isEmpty() )
00052 targetLabel->setText ( i18n (
"%1 in %2" ).arg ( titem->
primary ).arg ( titem->
prefix ) );
00053
else
00054 targetLabel->setText ( titem->
name );
00055
00056 connect ( removeButton, SIGNAL ( clicked() ),
this, SLOT (
accept() ) );
00057 connect ( cancelButton, SIGNAL ( clicked() ),
this, SLOT ( reject() ) );
00058
00059 setIcon ( SmallIcon (
"editdelete" ) );
00060
00061 progressBar->hide();
00062
00063
m_spitem = spitem;
00064
m_titem = titem;
00065
m_widget = widget;
00066
m_part = part;
00067
00068
00069
00070
init();
00071 }
00072
00073
00074 RemoveTargetDialog::~RemoveTargetDialog()
00075 {
00076 }
00077
00078 void RemoveTargetDialog::init()
00079 {
00080 QPtrList <SubprojectItem> subprojectItems =
m_widget->
allSubprojectItems();
00081
00082
TargetItem* titem = 0;
00083
00084
for (
SubprojectItem* spitem = subprojectItems.first(); spitem; spitem = subprojectItems.next() )
00085 {
00086
if (
m_titem->
name.isEmpty() )
00087
break;
00088
00089
for ( titem = spitem->
targets.first(); titem; titem = spitem->
targets.next() )
00090 {
00091
if (
m_titem->
name == titem->
name )
00092
continue;
00093
00094
if ( titem->
primary ==
"LTLIBRARIES" || titem->
primary ==
"PROGRAMS"
00095 || titem->
primary ==
"LIBRARIES" || titem->
primary ==
"JAVA" )
00096 {
00097
QString canonname = AutoProjectTool::canonicalize ( titem->
name );
00098
00099
if ( spitem->
variables[canonname +
"_LIBADD"].contains (
m_titem->
name ) > 0 ||
00100 spitem->
variables[canonname +
"_LDADD"].contains (
m_titem->
name ) > 0 )
00101 {
00102 dependencyListBox->insertItem ( SmallIcon (
"target_kdevelop" ), spitem->
path +
" (" + titem->
name +
")" );
00103
00104
dependentSubprojects.append ( spitem );
00105 }
00106 }
00107 }
00108 }
00109
00110
if ( dependencyListBox->count() == 0 )
00111 dependencyListBox->insertItem ( i18n(
"no dependency",
"<none>") );
00112 }
00113
00114 void RemoveTargetDialog::accept ()
00115 {
00116 progressBar->show();
00117 progressBar->
setFormat ( i18n (
"Removing Target... %p%" ) );
00118
00119 qApp->processEvents();
00120
00121
QString canonname = AutoProjectTool::canonicalize (
m_titem->
name );
00122
QString varname =
m_titem->
prefix +
"_" +
m_titem->
primary;
00123
00124
SubprojectItem* spitem = 0;
00125
TargetItem* titem = 0;
00126
00127 QMap <QString, QString> removeMap;
00128 QMap <QString, QString> replaceMap;
00129
00130
00131
for ( spitem =
dependentSubprojects.first(); spitem; spitem =
dependentSubprojects.next() )
00132 {
00133
for ( titem = spitem->
targets.first(); titem; titem = spitem->
targets.next() )
00134 {
00135
QString curVarname;
00136
QString curCanonname = AutoProjectTool::canonicalize ( titem->
name );
00137
QStringList dependencies;
00138
00139
if ( spitem->
variables[curCanonname +
"_LIBADD"].contains (
m_titem->
name ) )
00140 curVarname = curCanonname +
"_LIBADD";
00141
else
00142 curVarname = curCanonname +
"_LDADD";
00143
00144 dependencies = QStringList::split(
QRegExp(
"[ \t\n]"), spitem->
variables[curVarname]);
00145
00146
00147
00148
for ( uint i = 0; i < dependencies.size(); ++i )
00149 {
00150
QString s = dependencies[i];
00151
if ( s.contains (
m_titem->
name ) > 0 )
00152 dependencies.remove ( s );
00153 }
00154
00155
00156
if ( dependencies.count() == 0 )
00157 {
00158 removeMap.insert ( curVarname,
"" );
00159
00160 AutoProjectTool::removeFromMakefileam ( spitem->
path +
"/Makefile.am", removeMap );
00161
00162 removeMap.clear();
00163 }
00164
else
00165 {
00166 spitem->
variables[curVarname] = dependencies.join (
" " );
00167
00168 replaceMap.insert ( curVarname, spitem->
variables[curVarname] );
00169
00170 AutoProjectTool::modifyMakefileam ( spitem->
path +
"/Makefile.am", replaceMap );
00171
00172 replaceMap.clear();
00173 }
00174 }
00175 }
00176
00177
00178
if (
m_titem->
primary ==
"KDEICON" )
00179 removeMap.insert (
"KDE_ICON",
"" );
00180
else if (
m_titem->
primary ==
"KDEDOCS" )
00181 removeMap.insert (
"KDE_DOCS",
"" );
00182
else
00183 {
00184
00185
00186
QStringList targets = QStringList::split(
QRegExp(
"[ \t\n]"),
m_spitem->
variables[varname]);
00187
00188
if ( targets.count() > 1 )
00189 {
00190 targets.remove (
m_titem->
name );
00191
m_spitem->
variables[varname] = targets.join (
" " );
00192 replaceMap.insert ( varname,
m_spitem->
variables[varname] );
00193 AutoProjectTool::modifyMakefileam (
m_spitem->
path +
"/Makefile.am", replaceMap );
00194 replaceMap.clear();
00195 }
00196
else
00197 {
00198 removeMap.insert ( varname,
m_titem->
name );
00199 }
00200 }
00201
00202
00203
00204 removeMap.insert ( canonname +
"_SOURCES",
"" );
00205
00206
if (
m_titem->
primary ==
"PROGRAMS" ||
m_titem->
primary ==
"LTLIBRARIES" )
00207 {
00208 removeMap.insert ( canonname +
"_LDFLAGS",
"" );
00209 removeMap.insert ( canonname +
"_DEPENDENCIES",
"" );
00210 removeMap.insert ( canonname +
"_LDADD",
"" );
00211 removeMap.insert ( canonname +
"_LIBADD",
"" );
00212 }
00213
00214 AutoProjectTool::removeFromMakefileam (
m_spitem->
path +
"/Makefile.am", removeMap );
00215
00216 removeMap.clear();
00217
00218
00219
00220
if (
m_titem->
primary ==
"PROGRAMS" ||
m_titem->
primary ==
"LTLIBRARIES" )
00221 {
00222
for ( titem =
m_spitem->
targets.first(); titem; titem =
m_spitem->
targets.next() )
00223 {
00224
00225
if ( titem->
primary ==
"PROGRAMS" || titem->
primary ==
"LTLIBRARIES" )
00226 {
00227
QString curCanonname = AutoProjectTool::canonicalize ( titem->
name );
00228
00229
if (
m_spitem->
variables[curCanonname +
"_LIBADD"].isEmpty() )
00230 {
00231 removeMap.insert ( curCanonname +
"_LIBADD",
"" );
00232
00233
00234
00235 AutoProjectTool::removeFromMakefileam (
m_spitem->
path +
"/Makefile.am", removeMap );
00236
00237 removeMap.clear();
00238 }
00239 }
00240 }
00241 }
00242
00243
00244 progressBar->
setTotalSteps (
m_titem->
sources.count() );
00245
00246
QStringList fileList;
00247
00248
for (
FileItem* fitem =
m_titem->
sources.first(); fitem; fitem =
m_titem->
sources.next() )
00249 {
00250
if (removeCheckBox->isChecked())
00251 {
00252
00253
QStringList noInstHeaders = QStringList::split (
QRegExp (
"[ \t\n]" ),
m_spitem->
variables[
"noinst_HEADERS"] );
00254
00255
if ( noInstHeaders.contains ( fitem->
name ) )
00256 {
00257 noInstHeaders.remove ( fitem->
name );
00258
00259
m_spitem->
variables[
"noinst_HEADERS"] = noInstHeaders.join (
" " );
00260 replaceMap.insert (
"noinst_HEADERS",
m_spitem->
variables[
"noinst_HEADERS"] );
00261 AutoProjectTool::modifyMakefileam (
m_spitem->
path +
"/Makefile.am", replaceMap );
00262 replaceMap.clear();
00263 }
00264
00265 QFile::remove(
m_spitem->
path +
"/" + fitem->
name);
00266 }
00267
00268 fileList.append (
m_spitem->
path.mid (
m_part->
projectDirectory().length() + 1 ) +
"/" + fitem->
name );
00269
00270 qApp->processEvents();
00271
00272 progressBar->
setValue ( progressBar->
value() + 1 );
00273 }
00274
00275
m_widget->
emitRemovedFiles ( fileList );
00276
00277
m_spitem->
targets.remove (
m_titem );
00278
00279
00280 QDialog::accept();
00281 }