KDevelop API Documentation

buildtools/autotools/addexistingfilesdlg.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 ------------------- 00003 begin : Frag' mich was leichteres 00004 copyright : (C) 2002 by Victor Rder 00005 email : victor_roeder@gmx.de 00006 ***************************************************************************/ 00007 00008 /*************************************************************************** 00009 * * 00010 * This program is free software; you can redistribute it and/or modify * 00011 * it under the terms of the GNU General Public License as published by * 00012 * the Free Software Foundation; either version 2 of the License, or * 00013 * (at your option) any later version. * 00014 * * 00015 ***************************************************************************/ 00016 00019 #include <qapplication.h> 00020 #include <qgroupbox.h> 00021 #include <qlabel.h> 00022 //#include <qlistbox.h> 00023 #include <qpushbutton.h> 00024 #include <qlayout.h> 00025 #include <qtooltip.h> 00026 #include <qwhatsthis.h> 00027 #include <qpixmap.h> 00028 00029 #include <kdebug.h> 00030 #include <kfileview.h> 00031 #include <kguiitem.h> 00032 #include <kprogress.h> 00033 #include <kprocess.h> 00034 #include <kurldrag.h> 00035 #include <kmessagebox.h> 00036 #include <kmimetype.h> 00037 #include <kiconview.h> 00038 #include <ksqueezedtextlabel.h> 00039 00040 #include "autolistviewitems.h" 00041 00042 #include "autoprojectwidget.h" 00043 #include "autoprojectpart.h" 00044 00045 #include "kimporticonview.h" 00046 00047 #include "addexistingfilesdlg.h" 00048 00049 /* 00050 * Constructs a AddExistingFilesDialog which is a child of 'parent', with the 00051 * name 'name' and widget flags set to 'f'. 00052 * 00053 * The dialog will by default be modeless, unless you set 'modal' to 00054 * TRUE to construct a modal dialog. 00055 */ 00056 00057 AddExistingFilesDialog::AddExistingFilesDialog ( AutoProjectPart* part, AutoProjectWidget *widget, SubprojectItem* spitem, TargetItem* titem, QWidget* parent, const char* name, bool modal, WFlags fl ) 00058 : AddExistingDlgBase ( parent, name, modal, fl ) 00059 { 00060 m_spitem = spitem; 00061 m_titem = titem; 00062 00063 m_part = part; 00064 m_widget = widget; 00065 00066 KFile::Mode mode = KFile::Files; 00067 00068 if ( titem && spitem && titem->type() == ProjectItem::Target && spitem->type() == ProjectItem::Subproject ) 00069 { 00070 destStaticLabel->setText ( i18n ( "Target:" ) ); 00071 00072 if ( titem->name.isEmpty() ) 00073 { 00074 QString target = i18n ( "%1 in %2" ).arg ( titem->primary ).arg ( titem->prefix ); 00075 targetLabel->setText ( target ); 00076 destLabel->setText ( target ); 00077 } 00078 else 00079 { 00080 targetLabel->setText ( titem->name ); 00081 destLabel->setText ( titem->name ); 00082 } 00083 directoryLabel->setText ( spitem->path ); 00084 } 00085 00086 sourceSelector = new FileSelectorWidget ( m_part, mode, sourceGroupBox, "source file selector" ); 00087 sourceGroupBoxLayout->addWidget ( sourceSelector ); 00088 00089 importView = new KImportIconView ( i18n ( "Drag one or more files from above and drop it here!" ), destGroupBox, "destination icon view" ); 00090 destGroupBoxLayout->addWidget ( importView ); 00091 //destGroupBoxLayout->setStretchFactor(dir, 2); 00092 00093 QWidget::setTabOrder(sourceSelector, addAllButton); 00094 QWidget::setTabOrder(addAllButton, addSelectedButton); 00095 QWidget::setTabOrder(addSelectedButton, importView); 00096 QWidget::setTabOrder(importView, removeAllButton); 00097 QWidget::setTabOrder(removeAllButton, removeSelectedButton); 00098 QWidget::setTabOrder(removeSelectedButton, okButton); 00099 QWidget::setTabOrder(okButton, cancelButton); 00100 00101 sourceSelector->setFocus(); 00102 00103 setIcon ( SmallIcon ( "fileimport.png" ) ); 00104 00105 init(); 00106 } 00107 00108 00109 /* 00110 * Destroys the object and frees any allocated resources 00111 */ 00112 AddExistingFilesDialog::~AddExistingFilesDialog() 00113 { 00114 // no need to delete child widgets, Qt does it all for me 00115 } 00116 00117 00118 // void AddExistingFilesDialog::resizeEvent ( QResizeEvent* ev ) 00119 // { 00120 // AddExistingDlgBase::resizeEvent ( ev ); 00121 // //importView->update(); 00122 // } 00123 00124 00125 void AddExistingFilesDialog::init() 00126 { 00127 progressBar->hide(); 00128 00129 importView->setMode ( KIconView::Select ); 00130 importView->setItemsMovable ( false ); 00131 00132 connect ( okButton, SIGNAL ( clicked () ), this, SLOT ( slotOk () ) ); 00133 00134 connect ( addSelectedButton, SIGNAL ( clicked () ), this, SLOT ( slotAddSelected() ) ); 00135 connect ( addAllButton, SIGNAL ( clicked () ), this, SLOT ( slotAddAll() ) ); 00136 connect ( removeSelectedButton, SIGNAL ( clicked () ), this, SLOT ( slotRemoveSelected() ) ); 00137 connect ( removeAllButton, SIGNAL ( clicked () ), this, SLOT ( slotRemoveAll() ) ); 00138 00139 connect ( importView, SIGNAL ( dropped( QDropEvent* ) ), this, SLOT ( slotDropped ( QDropEvent* ) ) ); 00140 00141 importView->setSelectionMode ( KFile::Multi ); 00142 00143 Q_ASSERT( m_spitem ); 00144 sourceSelector->setDir ( m_spitem->path ); 00145 } 00146 00147 void AddExistingFilesDialog::importItems() 00148 { 00149 if( !importView->items() ) 00150 return; 00151 00152 // items added via button or drag 'n drop 00153 KFileItemListIterator itemList ( m_importList ); 00154 00155 // items already added to the importView 00156 KFileItemListIterator importedList ( *importView->items() ); 00157 00158 QListViewItem* child = m_titem->firstChild(); 00159 00160 QStringList duplicateList; 00161 00162 while ( child ) 00163 { 00164 FileItem* curItem = static_cast<FileItem*> ( child ); 00165 00166 itemList.toFirst(); 00167 00168 for ( ; itemList.current(); ++itemList ) 00169 { 00170 if ( ( *itemList )->name() == curItem->name ) 00171 { 00172 duplicateList.append ( ( *itemList )->name() ); 00173 m_importList.remove ( ( *itemList ) ); 00174 } 00175 } 00176 00177 child = child->nextSibling(); 00178 } 00179 00180 importedList.toFirst(); 00181 00182 for ( ; importedList.current(); ++importedList ) 00183 { 00184 itemList.toFirst(); 00185 00186 for ( ; itemList.current(); ++itemList ) 00187 { 00188 if ( ( *importedList )->name() == ( *itemList )->name() ) 00189 { 00190 m_importList.remove ( ( *itemList ) ); 00191 00192 // to avoid that a item is added twice 00193 if ( !duplicateList.remove ( ( *importedList )->name() ) ) 00194 { 00195 duplicateList.append ( ( *importedList )->name() ); 00196 } 00197 } 00198 } 00199 } 00200 00201 if ( duplicateList.count() > 0 ) 00202 { 00203 if ( KMessageBox::warningContinueCancelList ( this, i18n ( 00204 "The following file(s) already exist(s) in the target!\n" 00205 "Press Continue to import only the new files.\n" 00206 "Press Cancel to abort the complete import." ), 00207 duplicateList, "Warning", KGuiItem ( i18n ( "Continue" ) ) ) == KMessageBox::Cancel ) 00208 { 00209 m_importList.clear(); 00210 return; 00211 } 00212 } 00213 00214 itemList.toFirst(); 00215 00216 for ( ; itemList.current(); ++itemList ) 00217 { 00218 if ( !( *itemList )->isDir() ) 00219 { 00220 importView->insertItem ( ( *itemList ) ); 00221 } 00222 } 00223 00224 importView->somethingDropped ( true ); 00225 00226 m_importList.clear(); 00227 00228 importView->update (); 00229 } 00230 00231 void AddExistingFilesDialog::slotOk() 00232 { 00233 if ( importView->items()->count() == 0 ) QDialog::reject(); 00234 00235 progressBar->show(); 00236 progressBar->setFormat ( i18n ( "Importing... %p%" ) ); 00237 00238 qApp->processEvents(); 00239 00240 KFileItemListIterator items ( *importView->items() ); 00241 00242 // contains at the end only the imported files outside the subproject directory 00243 KFileItemList outsideList; 00244 00245 QStringList stringList; 00246 00247 for ( ; items.current(); ++items ) 00248 { 00249 // kdDebug ( 9000 ) << " **** " << ( *items )->url().directory() << "***** " << m_spitem->path << endl; 00250 if ( ( *items )->url().directory() != m_spitem->path ) 00251 { 00252 stringList.append ( ( *items )->name() ); 00253 outsideList.append ( ( *items ) ); 00254 } 00255 } 00256 00257 progressBar->setTotalSteps ( outsideList.count() + importView->items()->count() ); 00258 00259 if ( outsideList.count() > 0 ) 00260 { 00261 if ( KMessageBox::questionYesNoList ( this, i18n ( 00262 "The following file(s) are not in the Subproject directory.\n" 00263 "Press Link to add the files by creating symbolic links.\n" 00264 "Press Copy to copy the files into the directory." ), 00265 stringList, i18n("Warning"), KGuiItem ( i18n ( "Link (recommended)" ) ), KGuiItem ( i18n ( "Copy (not recommended)" ) ) ) == KMessageBox::No ) 00266 { 00267 // Copy files into the Subproject directory 00268 KFileItemListIterator it ( outsideList ) ; 00269 00270 for ( ; it.current(); ++it ) 00271 { 00272 KProcess proc; 00273 00274 proc << "cp"; 00275 proc << ( *it )->url().path(); 00276 proc << m_spitem->path; 00277 proc.start(KProcess::DontCare); 00278 00279 progressBar->setValue ( progressBar->value() + 1 ); 00280 } 00281 } 00282 else 00283 { 00284 // Link them into the Subproject directory 00285 KFileItemListIterator it ( outsideList ) ; 00286 00287 for ( ; it.current(); ++it ) 00288 { 00289 KProcess proc; 00290 00291 proc << "ln"; 00292 proc << "-s"; 00293 proc << ( *it )->url().path(); 00294 proc << m_spitem->path; 00295 proc.start(KProcess::DontCare); 00296 00297 progressBar->setValue ( progressBar->value() + 1 ); 00298 } 00299 } 00300 } 00301 00302 items.toFirst(); 00303 00304 QString canontargetname = AutoProjectTool::canonicalize ( m_titem->name ); 00305 QString varname; 00306 if( m_titem->primary == "PROGRAMS" || m_titem->primary == "LIBRARIES" || m_titem->primary == "LTLIBRARIES" ) 00307 varname = canontargetname + "_SOURCES"; 00308 else 00309 varname = m_titem->prefix + "_" + m_titem->primary; 00310 00311 QMap<QString,QString> replaceMap; 00312 FileItem* fitem = 0L; 00313 QStringList fileList; 00314 00315 for ( ; items.current(); ++items ) 00316 { 00317 m_spitem->variables [ varname ] += ( " " + ( *items )->name() ); 00318 replaceMap.insert ( varname, m_spitem->variables [ varname ] ); 00319 00320 fitem = m_widget->createFileItem ( ( *items )->name(), m_spitem ); 00321 m_titem->sources.append ( fitem ); 00322 m_titem->insertItem ( fitem ); 00323 00324 fileList.append ( m_spitem->path.mid ( m_part->projectDirectory().length() + 1 ) + "/" + ( *items )->name() ); 00325 00326 progressBar->setValue ( progressBar->value() + 1 ); 00327 } 00328 00329 m_widget->emitAddedFiles ( fileList ); 00330 00331 AutoProjectTool::modifyMakefileam ( m_spitem->path + "/Makefile.am", replaceMap ); 00332 00333 QDialog::accept(); 00334 00335 } 00336 00337 void AddExistingFilesDialog::slotAddSelected() 00338 { 00339 KFileItemListIterator it ( *sourceSelector->dirOperator()->selectedItems() ); 00340 00341 for ( ; it.current(); ++it ) 00342 { 00343 if ( ( *it )->url().isLocalFile() ) // maybe unnecessary 00344 { 00345 m_importList.append ( ( *it ) ); 00346 } 00347 } 00348 00349 importItems(); 00350 } 00351 00352 00353 void AddExistingFilesDialog::slotAddAll() 00354 { 00355 KFileItemListIterator it ( *sourceSelector->dirOperator()->view()->items() ); 00356 00357 for ( ; it.current(); ++it ) 00358 { 00359 if ( ( *it )->url().isLocalFile() ) // maybe unnecessary 00360 { 00361 m_importList.append ( ( *it ) ); 00362 } 00363 } 00364 00365 importItems(); 00366 } 00367 00368 void AddExistingFilesDialog::slotRemoveAll() 00369 { 00370 KURL::List deletedFiles; 00371 KFileItemListIterator it ( *importView->items() ); 00372 00373 for ( ; it.current(); ++it ) 00374 { 00375 kdDebug ( 9000 ) << "AddExistingFilesDialog::slotRemoveAll()" << endl; 00376 //deletedFiles.append ( ( *it )->url() ); 00377 if ( (*it ) ) importView->removeItem ( *it ); 00378 } 00379 00380 importView->somethingDropped ( false ); 00381 00382 importView->viewport()->update(); 00383 } 00384 00385 void AddExistingFilesDialog::slotRemoveSelected() 00386 { 00387 KFileItemListIterator items ( *importView->items() ); 00388 00389 KFileItemList* selectedList = (KFileItemList*) importView->selectedItems(); 00390 00391 KFileItem * deleteItem = 0L; 00392 00393 for ( ; items.current(); ++items ) 00394 { 00395 deleteItem = selectedList->first(); 00396 00397 while ( deleteItem ) 00398 { 00399 if ( deleteItem == ( *items ) ) 00400 { 00401 importView->removeItem ( deleteItem ); 00402 deleteItem = selectedList->current(); 00403 } 00404 else 00405 { 00406 deleteItem = selectedList->next(); 00407 } 00408 } 00409 } 00410 00411 if ( importView->items()->count() == 0 ) importView->somethingDropped ( false ); 00412 00413 importView->viewport()->update(); 00414 } 00415 00416 00417 void AddExistingFilesDialog::slotDropped ( QDropEvent* ev ) 00418 { 00419 kdDebug ( 9000 ) << "AddExistingFilesDialog::dropped()" << endl; 00420 00421 KURL::List urls; 00422 00423 KURLDrag::decode( ev, urls ); 00424 00425 KFileItem* item = 0L; 00426 KMimeType::Ptr type = 0L; 00427 00428 00429 for ( KURL::List::Iterator it = urls.begin(); it != urls.end(); ++it ) 00430 { 00431 if ( ( *it ).isLocalFile() ) // maybe unnecessary 00432 { 00433 type = KMimeType::findByURL ( ( *it ).url() ); 00434 00435 if ( type->name() != KMimeType::defaultMimeType() ) 00436 { 00437 item = new KFileItem ( ( *it ).url() , type->name(), 0 ); 00438 } 00439 else 00440 { 00441 // take a text-file-icon instead of the ugly question-mark-icon 00442 item = new KFileItem ( ( *it ).url(), "text/plain", 0 ); 00443 } 00444 00445 m_importList.append ( item ); 00446 } 00447 } 00448 00449 importItems(); 00450 } 00451 00452 #include "addexistingfilesdlg.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:38:53 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003