00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <qgroupbox.h>
00018 #include <qlayout.h>
00019
00020 #include <kprogress.h>
00021 #include <klocale.h>
00022 #include <kio/netaccess.h>
00023 #include <kprocess.h>
00024
00025 #include "autolistviewitems.h"
00026 #include "autosubprojectview.h"
00027
00028 #include "autoprojectwidget.h"
00029 #include "autoprojectpart.h"
00030
00031 #include "kimporticonview.h"
00032
00033 #include "urlutil.h"
00034
00035 #include "addexistingdirectoriesdlg.h"
00036
00037 AddExistingDirectoriesDialog::AddExistingDirectoriesDialog ( AutoProjectPart* part, AutoProjectWidget *widget, SubprojectItem* spitem, QWidget* parent, const char* name, bool modal, WFlags fl )
00038 : AddExistingDlgBase ( parent, name, modal, fl )
00039 {
00040 setIcon ( SmallIcon ( "fileimport.png" ) );
00041
00042 m_spitem = spitem;
00043
00044 m_part = part;
00045 m_widget = widget;
00046
00047 KFile::Mode mode = KFile::Directory;
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 sourceSelector = new FileSelectorWidget ( part, mode, sourceGroupBox, "source file selector" );
00058 sourceGroupBoxLayout->addWidget ( sourceSelector );
00059
00060 importView = new KImportIconView ( i18n("Drag one or more directories with an existing Makefile.am from the left view and drop it here."), destGroupBox, "destination icon view" );
00061 destGroupBoxLayout->addWidget ( importView );
00062
00063 setIcon ( SmallIcon ( "fileimport.png" ) );
00064
00065 QWidget::setTabOrder(sourceSelector, addAllButton);
00066 QWidget::setTabOrder(addAllButton, addSelectedButton);
00067 QWidget::setTabOrder(addSelectedButton, importView);
00068 QWidget::setTabOrder(importView, removeAllButton);
00069 QWidget::setTabOrder(removeAllButton, removeSelectedButton);
00070 QWidget::setTabOrder(removeSelectedButton, okButton);
00071 QWidget::setTabOrder(okButton, cancelButton);
00072
00073 sourceSelector->setFocus();
00074
00075 init();
00076 }
00077
00078
00079 AddExistingDirectoriesDialog::~AddExistingDirectoriesDialog()
00080 {
00081 }
00082
00083 void AddExistingDirectoriesDialog::init()
00084 {
00085 progressBar->hide();
00086
00087 importView->setMode ( KIconView::Select );
00088 importView->setItemsMovable ( false );
00089
00090 connect ( okButton, SIGNAL ( clicked () ), this, SLOT ( slotOk () ) );
00091
00092 connect ( addSelectedButton, SIGNAL ( clicked () ), this, SLOT ( slotAddSelected() ) );
00093 connect ( addAllButton, SIGNAL ( clicked () ), this, SLOT ( slotAddAll() ) );
00094 connect ( removeSelectedButton, SIGNAL ( clicked () ), this, SLOT ( slotRemoveSelected() ) );
00095 connect ( removeAllButton, SIGNAL ( clicked () ), this, SLOT ( slotRemoveAll() ) );
00096
00097 connect ( importView, SIGNAL ( dropped( QDropEvent* ) ), this, SLOT ( slotDropped ( QDropEvent* ) ) );
00098
00099 importView->setSelectionMode ( KFile::Multi );
00100
00101 sourceSelector->setDir ( m_spitem->path );
00102 }
00103
00104 void AddExistingDirectoriesDialog::importItems()
00105 {
00106 if( !importView->items() )
00107 return;
00108
00109
00110 KFileItemListIterator itemList ( m_importList );
00111
00112
00113 KFileItemListIterator importedList ( *importView->items() );
00114
00115 QStringList duplicateList;
00116
00117 importedList.toFirst();
00118
00119 for ( ; importedList.current(); ++importedList )
00120 {
00121 itemList.toFirst();
00122
00123 for ( ; itemList.current(); ++itemList )
00124 {
00125 if ( ( *importedList )->name() == ( *itemList )->name() )
00126 {
00127 m_importList.remove ( ( *itemList ) );
00128
00129
00130 if ( !duplicateList.remove ( ( *importedList )->name() ) )
00131 {
00132 duplicateList.append ( ( *importedList )->name() );
00133 }
00134 }
00135 }
00136 }
00137
00138 itemList.toFirst();
00139
00140 for ( ; itemList.current(); ++itemList )
00141 {
00142 KURL amURL = itemList.current()->url();
00143 amURL.addPath("Makefile.am");
00144 if (KIO::NetAccess::exists(amURL))
00145 {
00146 importView->insertItem ( ( *itemList ) );
00147 }
00148 }
00149
00150 importView->somethingDropped ( true );
00151
00152 m_importList.clear();
00153
00154 importView->update ();
00155 }
00156
00157 void AddExistingDirectoriesDialog::slotOk()
00158 {
00159 if ( importView->items()->count() == 0 ) QDialog::reject();
00160
00161 KFileItemListIterator items ( *importView->items() );
00162
00163 QStringList dirs;
00164
00165 for ( ; items.current(); ++items )
00166 {
00167
00168
00169 if (items.current()->url().path() != m_spitem->path)
00170 {
00171
00172
00173 KProcess proc;
00174
00175 proc << "cp";
00176 proc << "-r";
00177 proc << items.current()->url().path();
00178 proc << m_spitem->path;
00179 proc.start(KProcess::Block);
00180 }
00181 dirs << items.current()->name();
00182 }
00183
00184 for (QStringList::const_iterator it = dirs.begin(); it != dirs.end(); ++it)
00185 {
00186 QString name = *it;
00187
00188
00189 if (m_spitem->variables["SUBDIRS"].find("$(TOPSUBDIRS)") != -1)
00190 {
00191 QFile subdirsfile( m_spitem->path + "/subdirs" );
00192 if ( subdirsfile.open( IO_WriteOnly | IO_Append ) )
00193 {
00194 QTextStream subdirsstream( &subdirsfile );
00195 subdirsstream << name << endl;
00196 subdirsfile.close();
00197 }
00198 }
00199 else if (m_spitem->variables["SUBDIRS"].find("$(AUTODIRS)") != -1)
00200 {
00201 }
00202 else
00203 {
00204 m_spitem->variables["SUBDIRS"] += (" " + name);
00205 QMap<QString,QString> replaceMap;
00206 replaceMap.insert("SUBDIRS", m_spitem->variables["SUBDIRS"]);
00207 AutoProjectTool::modifyMakefileam(m_spitem->path + "/Makefile.am", replaceMap);
00208 }
00209
00210
00211 SubprojectItem *newitem = new SubprojectItem(m_spitem, name);
00212 newitem->subdir = name;
00213 newitem->path = m_spitem->path + "/" + name;
00214 newitem->variables["INCLUDES"] = m_spitem->variables["INCLUDES"];
00215 newitem->setOpen(true);
00216
00217
00218 QListViewItem *lastItem = m_spitem->firstChild();
00219 while (lastItem->nextSibling())
00220 lastItem = lastItem->nextSibling();
00221 if (lastItem != newitem)
00222 newitem->moveItem(lastItem);
00223
00224
00225
00226 QDir dir( m_spitem->path );
00227 QFile f( dir.filePath("Makefile.am") );
00228 if (f.exists()) {
00229 m_widget->getSubprojectView()->parse( newitem );
00230 } else {
00231 if (!f.open(IO_WriteOnly)) {
00232
00233 continue;
00234 }
00235 QTextStream stream(&f);
00236 stream << "INCLUDES = " << newitem->variables["INCLUDES"] << endl << "METASOURCES = AUTO" << endl;
00237 f.close();
00238 }
00239
00240
00241
00242
00243 if ( !m_part->isKDE() ) {
00244 QString projroot = m_part->projectDirectory() + "/";
00245 QString subdirectory = dir.path();
00246 QString relpath = subdirectory.replace(0, projroot.length(),"");
00247
00248 QString configurein = projroot + "configure.in";
00249
00250 QStringList list = AutoProjectTool::configureinLoadMakefiles(configurein);
00251 list.push_back( relpath + "/Makefile" );
00252 AutoProjectTool::configureinSaveMakefiles(configurein, list);
00253 }
00254
00255 m_part->needMakefileCvs();
00256
00257 }
00258 QDialog::accept();
00259 }
00260
00261 void AddExistingDirectoriesDialog::slotAddSelected()
00262 {
00263 KFileItemListIterator it ( *sourceSelector->dirOperator()->selectedItems() );
00264
00265 for ( ; it.current(); ++it )
00266 {
00267 QString relPath = URLUtil::extractPathNameRelative(m_part->projectDirectory(), ( *it )->url());
00268 if (relPath[relPath.length()-1] == '/')
00269 relPath = relPath.left(relPath.length()-1);
00270 if ( (relPath.isEmpty()) || (! m_widget->allSubprojects().contains( relPath )) )
00271 {
00272 m_importList.append ( ( *it ) );
00273 }
00274 }
00275
00276 importItems();
00277 }
00278
00279 void AddExistingDirectoriesDialog::slotAddAll()
00280 {
00281 KFileItemListIterator it ( *sourceSelector->dirOperator()->view()->items() );
00282
00283 for ( ; it.current(); ++it )
00284 {
00285 QString relPath = URLUtil::extractPathNameRelative(m_part->projectDirectory(), ( *it )->url());
00286 if (relPath[relPath.length()-1] == '/')
00287 relPath = relPath.left(relPath.length()-1);
00288 if ( (relPath.isEmpty()) || ( ! m_widget->allSubprojects().contains( relPath )) )
00289 {
00290 m_importList.append ( ( *it ) );
00291 }
00292 }
00293
00294 importItems();
00295 }
00296
00297 void AddExistingDirectoriesDialog::slotRemoveAll()
00298 {
00299 KURL::List deletedFiles;
00300 KFileItemListIterator it ( *importView->items() );
00301
00302 for ( ; it.current(); ++it )
00303 {
00304 kdDebug ( 9000 ) << "AddExistingDirectoriesDialog::slotRemoveAll()" << endl;
00305
00306 if ( (*it ) ) importView->removeItem ( *it );
00307 }
00308
00309 importView->somethingDropped ( false );
00310
00311 importView->viewport()->update();
00312 }
00313
00314 void AddExistingDirectoriesDialog::slotRemoveSelected()
00315 {
00316 KFileItemListIterator items ( *importView->items() );
00317
00318 KFileItemList* selectedList = (KFileItemList*) importView->selectedItems();
00319
00320 KFileItem * deleteItem = 0L;
00321
00322 for ( ; items.current(); ++items )
00323 {
00324 deleteItem = selectedList->first();
00325
00326 while ( deleteItem )
00327 {
00328 if ( deleteItem == ( *items ) )
00329 {
00330 importView->removeItem ( deleteItem );
00331 deleteItem = selectedList->current();
00332 }
00333 else
00334 {
00335 deleteItem = selectedList->next();
00336 }
00337 }
00338 }
00339
00340 if ( importView->items()->count() == 0 ) importView->somethingDropped ( false );
00341
00342 importView->viewport()->update();
00343 }
00344
00345 void AddExistingDirectoriesDialog::slotDropped ( QDropEvent* ev )
00346 {
00347 kdDebug ( 9000 ) << "AddExistingDirectoriesDialog::dropped()" << endl;
00348
00349 KURL::List urls;
00350
00351 KURLDrag::decode( ev, urls );
00352
00353 KFileItem* item = 0L;
00354 KMimeType::Ptr type = 0L;
00355
00356
00357 for ( KURL::List::Iterator it = urls.begin(); it != urls.end(); ++it )
00358 {
00359
00360 QString relPath = URLUtil::extractPathNameRelative(m_part->projectDirectory(), *it);
00361 if (relPath[relPath.length()-1] == '/')
00362 relPath = relPath.left(relPath.length()-1);
00363 if ( (relPath.isEmpty()) || ( ! m_widget->allSubprojects().contains( relPath )) )
00364 {
00365 type = KMimeType::findByURL ( ( *it ) );
00366
00367 if ( type->name() != KMimeType::defaultMimeType() )
00368 {
00369 item = new KFileItem ( ( *it ) , type->name(), 0 );
00370 }
00371 else
00372 {
00373 item = new KFileItem ( ( *it ), "inode/directory", 0 );
00374 }
00375
00376 m_importList.append ( item );
00377 }
00378 }
00379
00380 importItems();
00381 }
00382
00383 #include "addexistingdirectoriesdlg.moc"