00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "autoprojectwidget.h"
00016
00017 #include <qcheckbox.h>
00018 #include <qdom.h>
00019 #include <qfile.h>
00020 #include <qheader.h>
00021 #include <qpainter.h>
00022 #include <qptrstack.h>
00023 #include <qregexp.h>
00024 #include <qsplitter.h>
00025 #include <qstringlist.h>
00026 #include <qtextstream.h>
00027 #include <qtoolbutton.h>
00028 #include <qtooltip.h>
00029 #include <qwhatsthis.h>
00030 #include <qtimer.h>
00031
00032 #include <kdebug.h>
00033 #include <kfiledialog.h>
00034 #include <klistview.h>
00035 #include <kmessagebox.h>
00036 #include <kregexp.h>
00037 #include <kurl.h>
00038 #include <kfile.h>
00039 #include <kaction.h>
00040
00041 #include "kdevcore.h"
00042 #include "domutil.h"
00043 #include "misc.h"
00044 #include "choosetargetdialog.h"
00045
00046 #include "autolistviewitems.h"
00047
00048 #include "autoprojectpart.h"
00049 #include "autosubprojectview.h"
00050 #include "autodetailsview.h"
00051 #include "urlutil.h"
00052
00053 static QString nicePrimary( const QString &primary )
00054 {
00055 if ( primary == "PROGRAMS" )
00056 return i18n( "Program" );
00057 else if ( primary == "LIBRARIES" )
00058 return i18n( "Library" );
00059 else if ( primary == "LTLIBRARIES" )
00060 return i18n( "Libtool Library" );
00061 else if ( primary == "SCRIPTS" )
00062 return i18n( "Script" );
00063 else if ( primary == "HEADERS" )
00064 return i18n( "Header" );
00065 else if ( primary == "DATA" )
00066 return i18n( "Data" );
00067 else if ( primary == "JAVA" )
00068 return i18n( "Java" );
00069 else
00070 return QString::null;
00071 }
00072
00073
00074 AutoProjectWidget::AutoProjectWidget( AutoProjectPart *part, bool kde )
00075 : QVBox( 0, "auto project widget" )
00076 {
00077 m_part = part;
00078 m_kdeMode = kde;
00079 m_activeSubproject = 0;
00080 m_activeTarget = 0;
00081 m_shownSubproject = 0;
00082 m_choosenTarget = 0;
00083
00084 QSplitter *splitter = new QSplitter(Vertical, this);
00085
00086 initOverview ( splitter );
00087 initDetailview ( splitter );
00088
00089 initActions ();
00090 }
00091
00092
00093 AutoProjectWidget::~AutoProjectWidget()
00094 {}
00095
00096 void AutoProjectWidget::initOverview ( QWidget* parent )
00097 {
00098 QVBox * overviewBox = new QVBox( parent, "vertical overview box" );
00099
00100 QHBox *overviewButtonBox = new QHBox( overviewBox, "subproject button box" );
00101 overviewButtonBox->setMargin( 2 );
00102 overviewButtonBox->setSpacing( 2 );
00103
00104 addSubprojectButton = new QToolButton( overviewButtonBox );
00105 addSubprojectButton->setPixmap( SmallIcon( "folder_new" ) );
00106 QToolTip::add
00107 ( addSubprojectButton, i18n( "Add subproject" ) );
00108 QWhatsThis::add(addSubprojectButton, i18n("<b>Add subproject</b><p>Creates a new subproject in currently selected subproject."));
00109
00110
00111
00112
00113
00114 addTargetButton = new QToolButton( overviewButtonBox );
00115 addTargetButton->setPixmap( SmallIcon( "targetnew_kdevelop" ) );
00116 QToolTip::add
00117 ( addTargetButton, i18n( "Add target" ) );
00118 QWhatsThis::add(addTargetButton, i18n("<b>Add target</b><p>Adds a new target to the currently selected subproject. Target can be a binary program, library, script, also a collection of data or header files."));
00119
00120 addServiceButton = new QToolButton( overviewButtonBox );
00121 addServiceButton->setPixmap( SmallIcon( "servicenew_kdevelop" ) );
00122 QToolTip::add
00123 ( addServiceButton, i18n( "Add service" ) );
00124 QWhatsThis::add(addServiceButton, i18n("<b>Add service</b><p>Creates a .desktop file describing the service."));
00125
00126 addApplicationButton = new QToolButton( overviewButtonBox );
00127 addApplicationButton->setPixmap( SmallIcon( "window_new" ) );
00128 QToolTip::add
00129 ( addApplicationButton, i18n( "Add application" ) );
00130 QWhatsThis::add(addApplicationButton, i18n("<b>Add application</b><p>Creates an application .desktop file."));
00131
00132 buildSubprojectButton = new QToolButton( overviewButtonBox );
00133 buildSubprojectButton->setPixmap( SmallIcon( "launch" ) );
00134 QToolTip::add
00135 ( buildSubprojectButton, i18n( "Build" ) );
00136 QWhatsThis::add(buildSubprojectButton, i18n("<b>Build</b><p>Runs <b>make</b> from the directory of the selected subproject.<br>"
00137 "Environment variables and make arguments can be specified "
00138 "in the project settings dialog, <b>Make Options</b> tab."));
00139
00140 QWidget *spacer1 = new QWidget( overviewButtonBox );
00141 overviewButtonBox->setStretchFactor( spacer1, 1 );
00142
00143 subProjectOptionsButton = new QToolButton( overviewButtonBox );
00144 subProjectOptionsButton->setPixmap( SmallIcon( "configure" ) );
00145 QToolTip::add
00146 ( subProjectOptionsButton, i18n( "Options" ) );
00147 QWhatsThis::add(subProjectOptionsButton, i18n("<b>Options</b><p>Shows subproject options dialog that provides settings for compiler, include paths, prefixes and build order."));
00148
00149 overviewButtonBox->setMaximumHeight( subProjectOptionsButton->height() );
00150
00151 m_subprojectView = new AutoSubprojectView( this, m_part, overviewBox, "project overview widget" );
00152
00153 m_subprojectView->setResizeMode( QListView::LastColumn );
00154 m_subprojectView->setSorting( -1 );
00155 m_subprojectView->header() ->hide();
00156 m_subprojectView->addColumn( QString::null );
00157 }
00158
00159 void AutoProjectWidget::initDetailview ( QWidget* parent )
00160 {
00161 QVBox * targetBox = new QVBox( parent, "vertical target box" );
00162
00163 QHBox *targetButtonBox = new QHBox( targetBox, "target button box" );
00164 targetButtonBox->setMargin( 2 );
00165 targetButtonBox->setSpacing( 2 );
00166
00167 addNewFileButton = new QToolButton( targetButtonBox );
00168 addNewFileButton->setPixmap( SmallIcon( "filenew" ) );
00169 QToolTip::add
00170 ( addNewFileButton, i18n( "Create new file" ) );
00171 QWhatsThis::add(addNewFileButton, i18n("<b>Create new file</b><p>Creates a new file and adds it to a currently selected target."));
00172
00173 addExistingFileButton = new QToolButton( targetButtonBox );
00174 addExistingFileButton->setPixmap( SmallIcon( "fileimport" ) );
00175 QToolTip::add
00176 ( addExistingFileButton, i18n( "Add existing files" ) );
00177 QWhatsThis::add(addExistingFileButton, i18n("<b>Add existing files</b><p>Adds existing file to a currently selected target. Header files will not be included in SOURCES list of a target. "
00178 "They will be added to noinst_HEADERS instead."));
00179
00180 removeButton = new QToolButton( targetButtonBox );
00181 removeButton->setPixmap( SmallIcon( "editdelete" ) );
00182 QToolTip::add
00183 ( removeButton, i18n( "Remove" ) );
00184 QWhatsThis::add(removeButton, i18n("<b>Remove</b><p>Shows a list of targets dependent on the selected target or file and asks for removal. Also asks if the target or file should be removed from disk."));
00185
00186 buildTargetButton = new QToolButton( targetButtonBox );
00187 buildTargetButton->setPixmap( SmallIcon( "launch" ) );
00188 QToolTip::add
00189 ( buildTargetButton, i18n( "Build" ) );
00190 QWhatsThis::add(buildTargetButton, i18n("<b>Build target</b><p>Constructs a series of make commands to build the selected target. "
00191 "Also builds dependent targets."));
00192
00193 executeTargetButton = new QToolButton( targetButtonBox );
00194 executeTargetButton->setPixmap( SmallIcon( "exec") );
00195 QToolTip::add
00196 ( executeTargetButton, i18n( "Execute" ) );
00197 QWhatsThis::add(executeTargetButton, i18n("<b>Execute target</b><p> Executes target, if it's a program. Tries to build it, if that's not yet done."));
00198
00199 QWidget *spacer2 = new QWidget( targetButtonBox );
00200 targetButtonBox->setStretchFactor( spacer2, 1 );
00201
00202 targetOptionsButton = new QToolButton( targetButtonBox );
00203 targetOptionsButton->setPixmap( SmallIcon( "configure" ) );
00204 QToolTip::add
00205 ( targetOptionsButton, i18n( "Show options" ) );
00206 QWhatsThis::add(targetOptionsButton, i18n("<b>Options</b><p>Target options dialog that provides settings for linker flags and lists of dependencies and external libraries."));
00207
00208 targetButtonBox->setMaximumHeight( addNewFileButton->height() );
00209
00210 targetOptionsButton->setEnabled( false );
00211 addNewFileButton->setEnabled( false );
00212 addExistingFileButton->setEnabled( false );
00213 removeButton->setEnabled( true );
00214 buildTargetButton->setEnabled( true );
00215 executeTargetButton->setEnabled( true );
00216
00217 m_detailView = new AutoDetailsView( this, m_part, targetBox, "project details widget" );
00218 m_detailView->setRootIsDecorated( true );
00219 m_detailView->setResizeMode( QListView::LastColumn );
00220 m_detailView->setSorting( -1 );
00221 m_detailView->header() ->hide();
00222 m_detailView->addColumn( QString::null );
00223 }
00224
00225 void AutoProjectWidget::initActions()
00226 {
00227 connect( subProjectOptionsButton, SIGNAL( clicked() ), m_subprojectView, SLOT( slotSubprojectOptions() ) );
00228 connect( addSubprojectButton, SIGNAL( clicked() ), m_subprojectView, SLOT( slotAddSubproject() ) );
00229
00230 connect( addTargetButton, SIGNAL( clicked() ), m_subprojectView, SLOT( slotAddTarget() ) );
00231 connect( addServiceButton, SIGNAL( clicked() ), m_subprojectView, SLOT( slotAddService() ) );
00232 connect( addApplicationButton, SIGNAL( clicked() ), m_subprojectView, SLOT( slotAddApplication() ) );
00233 connect( buildSubprojectButton, SIGNAL( clicked() ), m_subprojectView, SLOT( slotBuildSubproject() ) );
00234
00235 connect( targetOptionsButton, SIGNAL( clicked() ), m_detailView, SLOT( slotTargetOptions() ) );
00236 connect( addNewFileButton, SIGNAL( clicked() ), m_detailView, SLOT( slotAddNewFile() ) );
00237 connect( addExistingFileButton, SIGNAL( clicked() ), m_detailView, SLOT( slotAddExistingFile() ) );
00238 connect( removeButton , SIGNAL( clicked() ), m_detailView, SLOT( slotRemoveDetail() ) );
00239 connect( buildTargetButton, SIGNAL( clicked() ), m_detailView, SLOT( slotBuildTarget() ) );
00240 connect( executeTargetButton, SIGNAL( clicked() ), m_detailView, SLOT( slotExecuteTarget() ) );
00241
00242 connect( m_subprojectView, SIGNAL( selectionChanged( QListViewItem* ) ),
00243 this, SLOT( slotOverviewSelectionChanged( QListViewItem* ) ) );
00244
00245 connect( m_detailView, SIGNAL( selectionChanged( QListViewItem* ) ),
00246 this, SLOT( slotDetailsSelectionChanged( QListViewItem* ) ) );
00247 }
00248
00249 AutoSubprojectView* AutoProjectWidget::getSubprojectView ()
00250 {
00251 return m_subprojectView;
00252 }
00253
00254 AutoDetailsView* AutoProjectWidget::getDetailsView ()
00255 {
00256 return m_detailView;
00257 }
00258
00259 void AutoProjectWidget::openProject( const QString &dirName )
00260 {
00261 m_subprojectView->loadMakefileams ( dirName );
00262 }
00263
00264
00265 void AutoProjectWidget::closeProject()
00266 {
00267 m_shownSubproject = 0;
00268 m_subprojectView->clear();
00269 m_detailView->clear();
00270 }
00271
00272 SubprojectItem* AutoProjectWidget::activeSubproject ()
00273 {
00274 return m_activeSubproject;
00275 }
00276
00277 TargetItem* AutoProjectWidget::activeTarget ()
00278 {
00279 return m_activeTarget;
00280 }
00281
00282 QStringList AutoProjectWidget::allSubprojects()
00283 {
00284 int prefixlen = m_part->projectDirectory().length() + 1;
00285 QStringList res;
00286
00287 QListViewItemIterator it( m_subprojectView );
00288 for ( ; it.current(); ++it )
00289 {
00290
00291
00292
00293 QString path = static_cast<SubprojectItem*>( it.current() ) ->path;
00294 res.append( path.mid( prefixlen ) );
00295 }
00296
00297 return res;
00298 }
00299
00300 QPtrList <SubprojectItem> AutoProjectWidget::allSubprojectItems()
00301 {
00302 QPtrList <SubprojectItem> res;
00303
00304 QListViewItemIterator it ( m_subprojectView );
00305
00306 for ( ; it.current(); ++it )
00307 {
00308
00309
00310
00311
00312 SubprojectItem* spitem = static_cast <SubprojectItem*> ( it.current() );
00313
00314 res.append ( spitem );
00315 }
00316
00317 return res;
00318 }
00319
00320 SubprojectItem* AutoProjectWidget::subprojectItemForPath(const QString & path, bool pathIsAbsolute)
00321 {
00322 kdDebug(9020) << "Looking for path " << path << endl;
00323
00324 int prefixLen = m_part->projectDirectory().length() + 1;
00325 for(QListViewItemIterator it = m_subprojectView;it.current();++it)
00326 {
00327 SubprojectItem* spitem = static_cast<SubprojectItem*>(it.current() );
00328 QString relpath = (spitem->path).mid(prefixLen);
00329 relpath = (relpath.isNull()) ? QString("") : relpath;
00330 kdDebug(9020) << " ... checking -" << spitem->path << "-" << endl;
00331 kdDebug(9020) << " ... (tailored: -" << relpath << "- against -" << (pathIsAbsolute ? path.mid(prefixLen) : path) << "- )" << endl;
00332 if ( relpath == (pathIsAbsolute ? path.mid(prefixLen) : path))
00333 {
00334 kdDebug(9020) << "Found it!" << endl;
00335 return spitem;
00336 }
00337 }
00338 kdDebug(9020) << "Not found" << endl;
00339 return NULL;
00340 }
00341
00342 QString AutoProjectWidget::pathForTarget(const TargetItem *titem) const {
00343
00344 if (!titem) return QString::null;
00345
00346 kdDebug(9020) << "Looking for target " << titem->name << endl;
00347 int prefixLen = m_part->projectDirectory().length() + 1;
00348 for(QListViewItemIterator it = m_subprojectView;it.current();++it)
00349 {
00350 SubprojectItem* spitem = static_cast<SubprojectItem*>(it.current() );
00351 kdDebug(9020) << "Checking: " << spitem->path << endl;
00352 if (spitem->targets.containsRef(titem)) {
00353 kdDebug(9020) << "Found it!" << endl;
00354 QString relpath = (spitem->path).mid(prefixLen);
00355 return (relpath.isNull()) ? QString("") : relpath;
00356 }
00357 }
00358 kdDebug(9020) << "Not found" << endl;
00359 return QString::null;
00360 }
00361
00362 QStringList AutoProjectWidget::allLibraries()
00363 {
00364 int prefixlen = m_part->projectDirectory().length() + 1;
00365 QStringList res;
00366
00367 QListViewItemIterator it( m_subprojectView );
00368 for ( ; it.current(); ++it )
00369 {
00370 SubprojectItem *spitem = static_cast<SubprojectItem*>( it.current() );
00371 QString path = spitem->path;
00372 QPtrListIterator<TargetItem> tit( spitem->targets );
00373 for ( ; tit.current(); ++tit )
00374 {
00375 QString primary = ( *tit ) ->primary;
00376 if ( primary == "LIBRARIES" || primary == "LTLIBRARIES" )
00377 {
00378 QString fullname = path + "/" + ( *tit ) ->name;
00379 res.append( fullname.mid( prefixlen ) );
00380 }
00381 }
00382 }
00383
00384 return res;
00385 }
00386
00387
00388 QStringList AutoProjectWidget::allFiles()
00389 {
00390 QPtrStack<QListViewItem> s;
00391 QMap<QString, bool> dict;
00392
00393 for ( QListViewItem * item = m_subprojectView->firstChild(); item;
00394 item = item->nextSibling() ? item->nextSibling() : s.pop() )
00395 {
00396 if ( item->firstChild() )
00397 s.push( item->firstChild() );
00398
00399 SubprojectItem *spitem = static_cast<SubprojectItem*>( item );
00400
00401 QString relPath = URLUtil::relativePath(m_part->projectDirectory(), spitem->path, URLUtil::SLASH_SUFFIX);
00402 QPtrListIterator<TargetItem> tit( spitem->targets );
00403 for ( ; tit.current(); ++tit )
00404 {
00405 QPtrListIterator<FileItem> fit( tit.current() ->sources );
00406 for ( ; fit.current(); ++fit ){
00407
00408 if((*fit)->is_subst)
00409 continue;
00410
00411 QFileInfo fileInfo( (*fit)->name );
00412 if( fileInfo.extension() == "ui" ){
00413 dict.insert( relPath + fileInfo.baseName() + ".h", true );
00414 dict.insert( relPath + fileInfo.baseName() + ".cpp", true );
00415 }
00416
00417 dict.insert( relPath + ( *fit ) ->name, true );
00418 }
00419 }
00420 }
00421
00422
00423
00424 QStringList res;
00425 QMap<QString, bool>::Iterator it = dict.begin();
00426 while( it != dict.end() ){
00427 res << it.key();
00428 ++it;
00429 }
00430
00431 return res;
00432 }
00433
00434
00435 QString AutoProjectWidget::subprojectDirectory()
00436 {
00437 if ( !selectedSubproject() )
00438 return QString::null;
00439
00440 return selectedSubproject() ->path;
00441 }
00442
00443
00444 void AutoProjectWidget::setActiveTarget( const QString &targetPath )
00445 {
00446 int prefixlen = m_part->projectDirectory().length() + 1;
00447
00448 m_activeSubproject = 0;
00449 m_activeTarget = 0;
00450
00451 QListViewItemIterator it( m_subprojectView );
00452 for ( ; it.current(); ++it )
00453 {
00454 SubprojectItem *spitem = static_cast<SubprojectItem*>( it.current() );
00455 QString path = spitem->path;
00456 QPtrListIterator<TargetItem> tit( spitem->targets );
00457 for ( ; tit.current(); ++tit )
00458 {
00459 QString primary = ( *tit ) ->primary;
00460 if ( primary != "PROGRAMS" && primary != "LIBRARIES"
00461 && primary != "LTLIBRARIES" && primary != "JAVA" )
00462 continue;
00463
00464 QString currentTargetPath = ( path + "/" + ( *tit ) ->name ).mid( prefixlen );
00465
00466 bool hasTarget = ( targetPath == currentTargetPath );
00467 ( *tit )->setBold( hasTarget );
00468 if ( hasTarget )
00469 {
00470 spitem->setBold( true );
00471 m_activeSubproject = spitem;
00472 m_activeTarget = ( *tit );
00473 m_subprojectView->setSelected( m_activeSubproject, true );
00474 m_subprojectView->ensureItemVisible ( m_activeSubproject );
00475 m_subprojectView->viewport() ->update();
00476 m_detailView->setSelected ( m_activeTarget, true );
00477 m_detailView->ensureItemVisible ( m_activeTarget );
00478 m_detailView->viewport()->update();
00479 }
00480 else
00481 {
00482
00483 spitem->setBold ( ( m_activeSubproject == spitem ) );
00484 m_detailView->viewport()->update();
00485 }
00486 }
00487 }
00488
00489 if ( m_activeSubproject == 0 &&
00490 m_activeTarget == 0 )
00491 {
00492 m_subprojectView->setSelected ( m_subprojectView->firstChild(), true );
00493 m_subprojectView->ensureItemVisible ( m_subprojectView->firstChild() );
00494 m_subprojectView->viewport()->update();
00495 }
00496 }
00497
00498
00499 QString AutoProjectWidget::activeDirectory()
00500 {
00501 if ( m_activeSubproject )
00502 return m_activeSubproject->path.mid( m_part->projectDirectory().length() + 1 );
00503 else
00504 {
00505
00506
00507
00508 return QString::null;
00509 }
00510 }
00511
00512
00513 void AutoProjectWidget::addFiles( const QStringList &list )
00514 {
00515 QDomDocument &dom = *m_part->projectDom();
00516 QStringList fileList = list;
00517
00518 if ( DomUtil::readBoolEntry( dom, "/kdevautoproject/general/useactivetarget" ) )
00519 {
00520 QStringList::iterator it;
00521
00522 QString fileName;
00523
00524 for ( it = fileList.begin(); it != fileList.end(); ++it )
00525 {
00526 int pos = ( *it ).findRev('/');
00527 if (pos != -1)
00528 {
00529 fileName = ( *it ).mid(pos+1);
00530 }
00531 else
00532 {
00533 fileName = ( *it );
00534 }
00535
00536
00537
00538
00539
00541 addToTarget(fileName, m_activeSubproject, m_activeTarget);
00542
00543
00544
00545
00546
00547
00548
00549
00550 }
00551
00552 emitAddedFiles ( list );
00553 }
00554 else
00555 {
00556
00557
00558
00559 QStringList doManually, doneAutomatically;
00560 for(QStringList::iterator it = fileList.begin();it!=fileList.end();++it)
00561 {
00562 bool autoAdded = false;
00563 QString relativeDir = URLUtil::directory(*it);
00564 SubprojectItem* spitem = subprojectItemForPath(relativeDir);
00565 if (spitem)
00566 {
00567 QPtrList<TargetItem> titemList = spitem->targets;
00568 if (titemList.count()==1) {
00569 addToTarget( URLUtil::filename(*it), spitem, titemList.first() );
00570 doneAutomatically.append(*it);
00571 autoAdded = true;
00572 }
00573 }
00574
00575 if (!autoAdded) doManually.append(*it);
00576 }
00577 if (doneAutomatically.count()>0) emitAddedFiles(doneAutomatically);
00578
00579
00580 if (doManually.count()>0) {
00581 ChooseTargetDialog chooseTargetDlg ( this, m_part, doManually, this, "choose target dialog" );
00582
00583
00584
00585 if ( chooseTargetDlg.exec() && chooseTargetDlg.neverAskAgainCheckBox->isChecked() )
00586 {
00587 DomUtil::writeBoolEntry( dom, "/kdevautoproject/general/useactivetarget", true );
00588 }
00589 }
00590 }
00591 }
00592
00593 void AutoProjectWidget::addToTarget(const QString & fileName, SubprojectItem* spitem, TargetItem* titem)
00594 {
00595 QString varname;
00597 if (AutoProjectPrivate::isHeader(fileName) &&
00598 ( titem->primary == "PROGRAMS" || titem->primary == "LIBRARIES" || titem->primary == "LTLIBRARIES" ) )
00599 {
00600 kdDebug ( 9020 ) << "Ignoring header file and adding it to noinst_HEADERS: " << fileName << endl;
00601 TargetItem* noinst_HEADERS_item = getSubprojectView()->findNoinstHeaders(spitem);
00602 FileItem *fitem = createFileItem( fileName, spitem );
00603 noinst_HEADERS_item->sources.append( fitem );
00604 noinst_HEADERS_item->insertItem( fitem );
00605 varname = "noinst_HEADERS";
00606 }
00607 else
00608 {
00609 FileItem * fitem = createFileItem( fileName, spitem );
00610 titem->sources.append( fitem );
00611 titem->insertItem( fitem );
00612
00613 QString canontargetname = AutoProjectTool::canonicalize( titem->name );
00614 varname = canontargetname + "_SOURCES";
00615 }
00616 spitem->variables[ varname ] += ( " " + fileName );
00617
00618 QMap<QString, QString> replaceMap;
00619 replaceMap.insert( varname, spitem->variables[ varname ] );
00620
00621 AutoProjectTool::modifyMakefileam( spitem->path + "/Makefile.am", replaceMap );
00622
00623 slotDetailsSelectionChanged(spitem);
00624 }
00625
00626 void AutoProjectWidget::removeFiles( const QStringList &list )
00627 {
00628 ( void ) list;
00629 }
00630
00631
00632 void AutoProjectWidget::slotOverviewSelectionChanged( QListViewItem *item )
00633 {
00634 if ( !item )
00635 return;
00636
00637
00638 if ( m_shownSubproject )
00639 {
00640
00641 kdDebug ( 9020 ) << "m_shownSubproject (before takeItem()): " << m_shownSubproject->subdir << endl;
00642
00643 QPtrListIterator<TargetItem> it1( m_shownSubproject->targets );
00644 for ( ; it1.current(); ++it1 )
00645 {
00646
00647
00648 kdDebug ( 9020 ) << "take child items of " << ( *it1 )->name << endl;
00649 if ( it1.current() ->parent() )
00650 {
00651 while ( ( *it1 ) ->firstChild() )
00652 {
00653 kdDebug ( 9020 ) << "take FileItem " << ( *it1 ) ->firstChild()->text(0) << endl;
00654 ( *it1 ) ->takeItem( ( *it1 ) ->firstChild() );
00655 }
00656 }
00657 m_detailView->takeItem( *it1 );
00658 }
00659 }
00660
00661
00662
00663 m_shownSubproject = static_cast<SubprojectItem*>( item );
00664
00665 kdDebug ( 9020 ) << "m_shownSubproject (after takeItem()): " << selectedSubproject()->subdir << endl;
00666
00667
00668 QPtrListIterator<TargetItem> it2( selectedSubproject()->targets );
00669 for ( ; it2.current(); ++it2 )
00670 {
00671 kdDebug ( 9020 ) << "insertItem in detail " << ( *it2 )->name << endl;
00672 m_detailView->insertItem( *it2 );
00673 QPtrListIterator<FileItem> it3( ( *it2 ) ->sources );
00674 for ( ; it3.current(); ++it3 )
00675 ( *it2 ) ->insertItem( *it3 );
00676 QString primary = ( *it2 ) ->primary;
00677 if ( primary == "PROGRAMS" || primary == "LIBRARIES"
00678 || primary == "LTLIBRARIES" || primary == "JAVA" )
00679 ( *it2 ) ->setOpen( true );
00680 }
00681
00682 targetOptionsButton->setEnabled ( false );
00683 addNewFileButton->setEnabled ( false );
00684 addExistingFileButton->setEnabled ( false );
00685 removeButton->setEnabled ( false );
00686 buildTargetButton->setEnabled ( false );
00687 executeTargetButton->setEnabled ( false );
00688 }
00689
00690
00691 void AutoProjectWidget::slotDetailsSelectionChanged( QListViewItem *item )
00692 {
00693 bool isTarget = false;
00694 bool isRegularTarget = false;
00695 bool isFile = false;
00696 bool isProgram = false;
00697
00698 if ( item )
00699 {
00700
00701
00702 ProjectItem * pvitem = static_cast<ProjectItem*>( item );
00703 TargetItem* titem = 0;
00704
00705 if ( pvitem->type() == ProjectItem::File )
00706 {
00707 titem = static_cast <TargetItem*> ( pvitem->parent() );
00708
00709 QString primary = titem->primary;
00710 if ( primary == "PROGRAMS" || primary == "LIBRARIES"
00711 || primary == "LTLIBRARIES" || primary == "JAVA" )
00712 {
00713 isRegularTarget = true;
00714 isFile = true;
00715 }
00716 }
00717 else
00718 {
00719 titem = static_cast <TargetItem*> ( pvitem );
00720 isTarget = true;
00721 }
00722
00723 QString primary = titem->primary;
00724 if ( primary == "PROGRAMS" || primary == "LIBRARIES"
00725 || primary == "LTLIBRARIES" || primary == "JAVA" )
00726 isRegularTarget = true;
00727
00728 if ( primary == "PROGRAMS" )
00729 isProgram = true;
00730
00731
00732
00733
00734 }
00735
00736 targetOptionsButton->setEnabled( isRegularTarget && !isFile );
00737 addNewFileButton->setEnabled( isTarget );
00738 addExistingFileButton->setEnabled( isTarget );
00739 removeButton->setEnabled ( true );
00740
00741 if ( isRegularTarget && isFile || isRegularTarget )
00742 {
00743 buildTargetButton->setEnabled ( true );
00744 if( isProgram )
00745 executeTargetButton->setEnabled ( true );
00746 }
00747 else
00748 {
00749 buildTargetButton->setEnabled ( false );
00750 executeTargetButton->setEnabled ( false );
00751 }
00752
00753
00754 }
00755
00756 TargetItem *AutoProjectWidget::selectedTarget()
00757 {
00758 ProjectItem * pvitem = static_cast<ProjectItem*>( m_detailView->selectedItem() );
00759 if ( !pvitem || ( pvitem->type() != ProjectItem::Target ) )
00760 return 0;
00761
00762 return static_cast<TargetItem*>( pvitem );
00763 }
00764
00765
00766 FileItem *AutoProjectWidget::selectedFile()
00767 {
00768 ProjectItem * pvitem = static_cast<ProjectItem*>( m_detailView->selectedItem() );
00769 if ( !pvitem || ( pvitem->type() != ProjectItem::File ) )
00770 return 0;
00771
00772 return static_cast<FileItem*>( pvitem );
00773 }
00774
00775 SubprojectItem* AutoProjectWidget::selectedSubproject()
00776 {
00777 ProjectItem * pvitem = static_cast <SubprojectItem*> ( m_subprojectView->selectedItem() );
00778
00779 if ( !pvitem || ( pvitem->type() != ProjectItem::Subproject ) )
00780 return 0;
00781
00782 return static_cast <SubprojectItem*> ( pvitem );
00783 }
00784
00785 TargetItem *AutoProjectWidget::createTargetItem( const QString &name,
00786 const QString &prefix, const QString &primary,
00787 bool take )
00788 {
00789 bool group = !( primary == "PROGRAMS" || primary == "LIBRARIES"
00790 || primary == "LTLIBRARIES" || primary == "JAVA" );
00791 bool docgroup = ( primary == "KDEDOCS" );
00792 bool icongroup = ( primary == "KDEICON" );
00793
00794 QString text;
00795 if ( docgroup )
00796 text = i18n( "Documentation data" );
00797 else if ( icongroup )
00798 text = i18n( "Icon data in %1" ).arg( prefix );
00799 else if ( group )
00800 text = i18n( "%1 in %2" ).arg( nicePrimary( primary ) ).arg( prefix );
00801 else
00802 text = i18n( "%1 (%2 in %3)" ).arg( name ).arg( nicePrimary( primary ) ).arg( prefix );
00803
00804
00805
00806 TargetItem *titem = new TargetItem( m_detailView, group, text );
00807 titem->name = name;
00808 titem->prefix = prefix;
00809 titem->primary = primary;
00810 if( take )
00811 m_detailView->takeItem( titem );
00812
00813 return titem;
00814 }
00815
00816
00817 FileItem *AutoProjectWidget::createFileItem( const QString &name, SubprojectItem *subproject )
00818 {
00819 bool is_subst;
00820 if(name.find("$(") == 0 || name.find("${") == 0)
00821 is_subst = true;
00822 else
00823 is_subst = false;
00824
00825 FileItem * fitem = new FileItem( m_subprojectView, name, is_subst );
00826 fitem->uiFileLink = m_detailView->getUiFileLink(subproject->relativePath()+"/", name );
00827 m_subprojectView->takeItem( fitem );
00828 fitem->name = name;
00829
00830 return fitem;
00831 }
00832
00833
00834 void AutoProjectWidget::emitAddedFiles( const QStringList &fileList )
00835 {
00836 emit m_part->addedFilesToProject( fileList );
00837 }
00838
00839 void AutoProjectWidget::emitAddedFile( const QString &name )
00840 {
00841 QStringList fileList;
00842 fileList.append ( name );
00843 emit m_part->addedFilesToProject( fileList );
00844 }
00845
00846 void AutoProjectWidget::emitRemovedFiles( const QStringList &fileList )
00847 {
00848 emit m_part->removedFilesFromProject( fileList );
00849 }
00850
00851 void AutoProjectWidget::emitRemovedFile( const QString &name )
00852 {
00853 QStringList fileList;
00854 fileList.append ( name );
00855 emit m_part->removedFilesFromProject( fileList );
00856 }
00857
00858 void AutoProjectWidget::restoreSession ( const QDomElement* el )
00859 {
00860 Q_UNUSED( el );
00861 }
00862
00863 void AutoProjectWidget::saveSession ( QDomElement* el )
00864 {
00865 kdDebug ( 9020 ) << "************** Saving session data of AutoProjectWidget: " << endl;
00866
00867 if ( m_activeTarget && m_activeSubproject )
00868 {
00869 QDomDocument domDoc = el->ownerDocument();
00870
00871 QString activeTargetPath = m_activeSubproject->path.mid ( m_part->project()->projectDirectory().length() + 1 );
00872 activeTargetPath = activeTargetPath + "/" + m_activeTarget->name;
00873
00874 QDomElement generalEl = domDoc.createElement("general");
00875
00876 kdDebug ( 9020 ) << "************** Saving session data of AutoProjectWidget: " << activeTargetPath << endl;
00877
00878 generalEl.setAttribute("activetarget", activeTargetPath);
00879 el->appendChild(generalEl);
00880 }
00881 }
00882
00883 void AutoProjectWidget::setActiveSubproject( SubprojectItem * spitem )
00884 {
00885 m_activeSubproject = spitem;
00886 }
00887
00888 void AutoProjectWidget::focusInEvent( QFocusEvent * )
00889 {
00890 switch (m_lastFocusedView)
00891 {
00892 case DetailsView:
00893 m_detailView->setFocus();
00894 break;
00895 case SubprojectView:
00896 default:
00897 m_subprojectView->setFocus();
00898 }
00899 }
00900
00901 void AutoProjectWidget::setLastFocusedView( AutoProjectView view )
00902 {
00903 m_lastFocusedView = view;
00904 }
00905
00906 #include "autoprojectwidget.moc"