removefiledlg.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "removefiledlg.h"
00013
00014 #include <qcheckbox.h>
00015 #include <qgroupbox.h>
00016 #include <qfile.h>
00017 #include <qlabel.h>
00018 #include <qlayout.h>
00019 #include <qpushbutton.h>
00020 #include <qregexp.h>
00021
00022 #include <kbuttonbox.h>
00023 #include <kdebug.h>
00024 #include <kdialog.h>
00025 #include <ksqueezedtextlabel.h>
00026
00027 #include "autolistviewitems.h"
00028
00029 #include "misc.h"
00030 #include "autoprojectpart.h"
00031 #include "autoprojectwidget.h"
00032 #include "autodetailsview.h"
00033
00034 static bool fileListContains(const QPtrList<FileItem> &list, const QString &name)
00035 {
00036 QPtrListIterator<FileItem> it(list);
00037 for (; it.current(); ++it)
00038 if ((*it)->text(0) == name)
00039 return true;
00040 return false;
00041 }
00042
00043
00044 RemoveFileDialog::RemoveFileDialog(AutoProjectWidget *widget, AutoProjectPart* part, SubprojectItem *spitem,
00045 TargetItem *item, const QString &filename,
00046 QWidget *parent, const char *name)
00047 : RemoveFileDlgBase(parent, name, true)
00048 {
00049 removeFromTargetsCheckBox = 0;
00050
00051 QStringList targets;
00052
00053 QPtrListIterator<TargetItem> it(spitem->targets);
00054 for (; it.current(); ++it)
00055 if (fileListContains((*it)->sources, filename))
00056 targets.append((*it)->name);
00057
00058 if (targets.count() > 1)
00059 {
00060 removeFromTargetsCheckBox = new QCheckBox( fileGroupBox, "removeFromTargetsCheckBox" );
00061 removeFromTargetsCheckBox->setMinimumSize( QSize( 0, 45 ) );
00062 fileLayout->addWidget( removeFromTargetsCheckBox );
00063
00064 QString joinedtargets = " *" + targets.join("\n *");
00065 removeFromTargetsCheckBox->setText ( i18n ( "The file %1 is still used by the following targets:\n%2\n"
00066 "Remove it from all of them?").arg(filename).arg(joinedtargets) );
00067 setMinimumSize(QSize(size().width(), size().height() + removeFromTargetsCheckBox->size().height()*2) );
00068 }
00069
00070 removeLabel->setText ( i18n ( "Do you really want to remove <b>%1</b>?" ).arg ( filename ) );
00071
00072 directoryLabel->setText ( spitem->path );
00073 if ( item->name.isEmpty() )
00074 targetLabel->setText ( i18n ( "%1 in %2" ).arg ( item->primary ).arg ( item->prefix ) );
00075 else
00076 targetLabel->setText ( item->name );
00077
00078 connect ( removeButton, SIGNAL ( clicked() ), this, SLOT ( accept() ) );
00079 connect ( cancelButton, SIGNAL ( clicked() ), this, SLOT ( reject() ) );
00080
00081 setIcon ( SmallIcon ( "editdelete.png" ) );
00082
00083 m_widget = widget;
00084 m_part = part;
00085 subProject = spitem;
00086 target = item;
00087 fileName = filename;
00088 }
00089
00090
00091 RemoveFileDialog::~RemoveFileDialog()
00092 {}
00093
00094
00095 void RemoveFileDialog::accept()
00096 {
00097 m_widget->emitRemovedFile ( subProject->path.mid ( m_part->projectDirectory().length() + 1 ) + "/" + fileName );
00098
00099 QMap<QString,QString> replaceMap;
00100
00101 if (removeFromTargetsCheckBox && removeFromTargetsCheckBox->isChecked()) {
00102 QPtrListIterator<TargetItem> it(subProject->targets);
00103 for (; it.current(); ++it) {
00104 if ((*it) != target && fileListContains((*it)->sources, fileName)) {
00105 FileItem *fitem = static_cast<FileItem*>((*it)->firstChild());
00106 while (fitem) {
00107 FileItem *nextitem = static_cast<FileItem*>(fitem->nextSibling());
00108 if (fitem->text(0) == fileName) {
00109 QListView *lv = fitem->listView();
00110 lv->setSelected(fitem, false);
00111 (*it)->sources.remove(fitem);
00112 }
00113 fitem = nextitem;
00114 }
00115 QString canontargetname = AutoProjectTool::canonicalize((*it)->name);
00116 QString varname;
00117 if( (*it)->primary == "PROGRAMS" || (*it)->primary == "LIBRARIES" || (*it)->primary == "LTLIBRARIES" )
00118 varname = canontargetname + "_SOURCES";
00119 else
00120 varname = (*it)->prefix + "_" + (*it)->primary;
00121 QStringList sources = QStringList::split(QRegExp("[ \t\n]"), subProject->variables[varname]);
00122 sources.remove(fileName);
00123 subProject->variables[varname] = sources.join(" ");
00124 replaceMap.insert(varname, subProject->variables[varname]);
00125 }
00126 }
00127 }
00128
00129 QString fileItemName;
00130 FileItem *fitem = static_cast<FileItem*>(target->firstChild());
00131 while (fitem) {
00132 if (fitem->text(0) == fileName) {
00133 QListView *lv = fitem->listView();
00134 lv->setSelected(fitem, false);
00135 fileItemName = fitem->name;
00136 target->sources.remove(fitem);
00137 break;
00138 }
00139 fitem = static_cast<FileItem*>(fitem->nextSibling());
00140 }
00141 QString canontargetname = AutoProjectTool::canonicalize(target->name);
00142 QString varname;
00143 if( target->primary == "PROGRAMS" || target->primary == "LIBRARIES" || target->primary == "LTLIBRARIES" )
00144 varname = canontargetname + "_SOURCES";
00145 else
00146 varname = target->prefix + "_" + target->primary;
00147 QStringList sources = QStringList::split(QRegExp("[ \t\n]"), subProject->variables[varname]);
00148 sources.remove(fileName);
00149 subProject->variables[varname] = sources.join(" ");
00150 replaceMap.insert(varname, subProject->variables[varname]);
00151
00152 AutoProjectTool::modifyMakefileam(subProject->path + "/Makefile.am", replaceMap);
00153
00154
00155 QDomDocument &dom = *(m_part->projectDom());
00156
00157 QDomElement el = dom.documentElement();
00158 QDomNode el2 = el.namedItem("kdevautoproject");
00159 QDomNode el3 = el2.namedItem("subclassing");
00160
00161 QDomNode n = el3.firstChild();
00162 QValueList<QDomNode> nodesToRemove;
00163 while ( !n.isNull() ) {
00164 QDomNamedNodeMap attr = n.attributes();
00165 QString fpath = subProject->path + QString("/") + fileItemName;
00166 QString relpath = fpath.remove(0, m_part->projectDirectory().length());
00167 if ((attr.item(0).nodeValue() == relpath)
00168 || (attr.item(1).nodeValue() == relpath) )
00169 nodesToRemove.append(n);
00170 n = n.nextSibling();
00171 }
00172 QValueList<QDomNode>::iterator it;
00173 for ( it = nodesToRemove.begin(); it != nodesToRemove.end(); ++it )
00174 el3.removeChild(*it);
00175
00176 if (removeCheckBox->isChecked())
00177 QFile::remove(subProject->path + "/" + fileName);
00178
00179 QDialog::accept();
00180 }
00181
00182 #include "removefiledlg.moc"
This file is part of the documentation for KDevelop Version 3.1.2.