KDevelop API Documentation

genericproject_widget.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 Roberto Raggi                                      *
00003  *   roberto@kdevelop.org                                                  *
00004  *   Copyright (C) 2003 Alexander Dymo                                     *
00005  *   cloudtemple@mksat.net                                                 *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  ***************************************************************************/
00013 
00014 #include "genericproject_part.h"
00015 #include "genericproject_widget.h"
00016 #include "overviewlistview.h"
00017 #include "detailslistview.h"
00018 #include "genericlistviewitem.h"
00019 
00020 #include "kdevcore.h"
00021 #include "kdevpartcontroller.h"
00022 
00023 #include <kparts/part.h>
00024 #include <klibloader.h>
00025 #include <kurl.h>
00026 #include <kdebug.h>
00027 #include <kiconloader.h>
00028 #include <kaction.h>
00029 #include <kpopupmenu.h>
00030 #include <klistview.h>
00031 #include <klocale.h>
00032 #include <kinputdialog.h>
00033 #include <kmessagebox.h>
00034 #include <kio/netaccess.h>
00035 #include <kfiledialog.h>
00036 
00037 #include <qsplitter.h>
00038 #include <qtooltip.h>
00039 #include <qwhatsthis.h>
00040 #include <qtoolbutton.h>
00041 #include <qheader.h>
00042 #include <qdir.h>
00043 #include <qfile.h>
00044 
00045 #include "kdevbuildsystem.h"
00046 #include "removesubprojectdialog.h"
00047 #include "kdevcreatefile.h"
00048 
00049 GenericProjectWidget::GenericProjectWidget(GenericProjectPart *part)
00050     : QVBox( 0, "GenericProjectWidget" ), m_part( part ), m_activeGroup( 0 ), m_activeTarget( 0 )
00051 {
00052     QSplitter* splitter = new QSplitter( Vertical, this );
00053     initOverviewListView( splitter );
00054     initDetailsListView( splitter );
00055 
00056     initActions();
00057 
00058     connect( m_part, SIGNAL(mainGroupChanged(BuildGroupItem*)),
00059         this, SLOT(slotMainGroupChanged(BuildGroupItem*)) );
00060 }
00061 
00062 GenericProjectWidget::~GenericProjectWidget()
00063 {
00064 }
00065 
00066 void GenericProjectWidget::initOverviewListView( QSplitter * splitter )
00067 {
00068     QVBox* vbox = new QVBox( splitter );
00069 
00070     QHBox* buttonBox = new QHBox( vbox );
00071     buttonBox->setMargin( 2 );
00072     buttonBox->setSpacing( 2 );
00073 
00074     QToolButton* btn = 0;
00075 
00076     btn = new QToolButton( buttonBox );
00077     btn->setPixmap( SmallIcon("group_new") );
00078     QToolTip::add( btn, i18n("Add new group") );
00079     QWhatsThis::add( btn, i18n("<b>Add new group</b><p>Adds a new group of targets and files. "
00080         "Group is usually a subdirectory in the project directory but that depends on an underlying build system.") );
00081     connect(btn, SIGNAL(clicked()), this, SLOT(slotNewGroup()));
00082 
00083     btn = new QToolButton( buttonBox );
00084     btn->setPixmap( SmallIcon("targetnew_kdevelop") );
00085     QToolTip::add( btn, i18n("Add new target") );
00086     QWhatsThis::add( btn, i18n("<b>Add new target</b><p>Adds a new target. "
00087         "Target is usually an application, static or shared library but that depends on an underlying build system.") );
00088     connect(btn, SIGNAL(clicked()), this, SLOT(slotNewTarget()));
00089 
00090     btn = new QToolButton( buttonBox );
00091     btn->setPixmap( SmallIcon("launch") );
00092     QToolTip::add( btn, i18n("Build") );
00093     QWhatsThis::add( btn, i18n("<b>Build</b><p>Executes all commands necessary to build the current group.") );
00094     connect(btn, SIGNAL(clicked()), this, SLOT(slotBuildGroup()));
00095 
00096     QWidget *spacer1 = new QWidget( buttonBox );
00097     buttonBox->setStretchFactor( spacer1, 1 );
00098 
00099     btn = new QToolButton( buttonBox );
00100     btn->setPixmap( SmallIcon("configure") );
00101     QToolTip::add( btn, i18n("Configure group") );
00102     QWhatsThis::add( btn, i18n("<b>Configure group</b><p>Opens a group configuration dialog supplied by a build system plugin.") );
00103     connect(btn, SIGNAL(clicked()), this, SLOT(slotConfigureGroup()));
00104 
00105     buttonBox->setMaximumHeight( btn->height() );
00106 
00107     m_overviewListView = new OverviewListView( m_part, vbox, "GroupListView" );
00108 
00109     m_overviewListView->setResizeMode( QListView::LastColumn );
00110     m_overviewListView->setSorting( -1 );
00111     m_overviewListView->header()->hide();
00112     m_overviewListView->addColumn( QString::null );
00113 
00114     connect( m_overviewListView, SIGNAL(selectionChanged(QListViewItem*)),
00115             this, SLOT(slotItemSelected(QListViewItem*)) );
00116 
00117     connect( this, SIGNAL(groupSelected(BuildGroupItem*)),
00118             this, SLOT(showDetails(BuildGroupItem*)) );
00119 
00120     connect(m_overviewListView, SIGNAL(contextMenu(KListView *, QListViewItem *, const QPoint &)),
00121             this, SLOT(showGroupContextMenu(KListView *, QListViewItem *, const QPoint &)));
00122 }
00123 
00124 void GenericProjectWidget::initDetailsListView( QSplitter * splitter )
00125 {
00126     QVBox* vbox = new QVBox( splitter );
00127 
00128     QHBox* buttonBox = new QHBox( vbox );
00129     buttonBox->setMargin( 2 );
00130     buttonBox->setSpacing( 2 );
00131 
00132     QToolButton* btn = 0;
00133 
00134     btn = new QToolButton( buttonBox );
00135     btn->setPixmap( SmallIcon("filenew") );
00136     QToolTip::add( btn, i18n("New file") );
00137     QWhatsThis::add( btn, i18n("<b>New file</b><p>Creates a new file and adds it to a current target.") );
00138     connect(btn, SIGNAL(clicked()), this, SLOT(slotNewFile()));
00139 
00140     btn = new QToolButton( buttonBox );
00141     btn->setPixmap( SmallIcon("fileimport") );
00142     QToolTip::add( btn, i18n("Add files") );
00143     QWhatsThis::add( btn, i18n("<b>Add files</b><p>Adds existing files to a current target.") );
00144     connect(btn, SIGNAL(clicked()), this, SLOT(slotAddFiles()));
00145 
00146     btn = new QToolButton( buttonBox );
00147     btn->setPixmap( SmallIcon("editdelete") );
00148     QToolTip::add( btn, i18n("Remove target or file") );
00149     QWhatsThis::add( btn, i18n("<b>Remove target or file</b><p>Removes current target or file.") );
00150     connect(btn, SIGNAL(clicked()), this, SLOT(slotDeleteTargetOrFile()));
00151 
00152 /*    btn = new QToolButton( buttonBox );
00153     btn->setPixmap( SmallIcon("editdelete") );
00154     QToolTip::add( btn, i18n("Remove file") );
00155     QWhatsThis::add( btn, i18n("<b></b><p>") );
00156     connect(btn, SIGNAL(clicked()), this, SLOT(slotDeleteFile()));
00157 */
00158     btn = new QToolButton( buttonBox );
00159     btn->setPixmap( SmallIcon("launch") );
00160     QToolTip::add( btn, i18n("Build target") );
00161     QWhatsThis::add( btn, i18n("<b>Build target</b><p>Executes all commands necessary to build the current target.") );
00162     connect(btn, SIGNAL(clicked()), this, SLOT(slotBuildTarget()));
00163 
00164 
00165     QWidget *spacer1 = new QWidget( buttonBox );
00166     buttonBox->setStretchFactor( spacer1, 1 );
00167 
00168     btn = new QToolButton( buttonBox );
00169     btn->setPixmap( SmallIcon("configure") );
00170     QToolTip::add( btn, i18n("Configure target or file") );
00171     QWhatsThis::add( btn, i18n("<b>Configure target or file</b><p>Opens a target or file configuration dialog supplied by a build system plugin.") );
00172     connect(btn, SIGNAL(clicked()), this, SLOT(slotConfigureTargetOrFile()));
00173 
00174     buttonBox->setMaximumHeight( btn->height() );
00175 
00176     m_detailsListView = new DetailsListView( m_part, vbox, "DetailsListView" );
00177 
00178     m_detailsListView->setResizeMode( QListView::LastColumn );
00179     m_detailsListView->setSorting( -1 );
00180     m_detailsListView->header()->hide();
00181     m_detailsListView->addColumn( QString::null );
00182 
00183     connect( m_detailsListView, SIGNAL(clicked(QListViewItem*)),
00184         this, SLOT(slotItemSelected(QListViewItem*)) );
00185     connect( m_detailsListView, SIGNAL(executed(QListViewItem*)),
00186         this, SLOT(slotItemExecuted(QListViewItem*)) );
00187     connect( m_detailsListView, SIGNAL(returnPressed(QListViewItem*)),
00188         this, SLOT(slotItemExecuted(QListViewItem*)) );
00189 
00190     connect( this, SIGNAL(targetSelected(BuildTargetItem*)),
00191         this, SLOT(showTargetDetails(BuildTargetItem*)) );
00192     connect( this, SIGNAL(fileExecuted(BuildFileItem*)),
00193         this, SLOT(showFileDetails(BuildFileItem*)) );
00194     connect(m_detailsListView, SIGNAL(contextMenu(KListView *, QListViewItem *, const QPoint &)),
00195         this, SLOT(showDetailContextMenu(KListView *, QListViewItem *, const QPoint &)));
00196 
00197 }
00198 
00199 void GenericProjectWidget::slotMainGroupChanged( BuildGroupItem * mainGroup )
00200 {
00201     m_overviewListView->clear();
00202 
00203     m_groupToItem.clear();
00204     m_targetToItem.clear();
00205     m_fileToItem.clear();
00206 
00207     if( !mainGroup )
00208         return;
00209 
00210     GenericGroupListViewItem* mainItem = new GenericGroupListViewItem( m_overviewListView, mainGroup );
00211     mainItem->setOpen( true );
00212     fillGroupItem( mainGroup, mainItem );
00213 }
00214 
00215 void GenericProjectWidget::fillGroupItem( BuildGroupItem * group, GenericGroupListViewItem * item )
00216 {
00217     m_groupToItem.insert( group, item );
00218 
00219     QValueList<BuildGroupItem*> groups = group->groups();
00220     QValueListIterator<BuildGroupItem*> it = groups.begin();
00221     while( it != groups.end() ){
00222         GenericGroupListViewItem* createdItem = new GenericGroupListViewItem( item, *it );
00223         createdItem->setOpen( (*it)->groups().size() > 0 );
00224         fillGroupItem( *it, createdItem );
00225 
00226         ++it;
00227     }
00228 }
00229 
00230 void GenericProjectWidget::slotItemSelected( QListViewItem * item )
00231 {
00232     GenericGroupListViewItem* groupItem = dynamic_cast<GenericGroupListViewItem*>( item );
00233     GenericTargetListViewItem* targetItem = dynamic_cast<GenericTargetListViewItem*>( item );
00234 //  GenericFileListViewItem* fileItem = dynamic_cast<GenericFileListViewItem*>( item );
00235 
00236     if( groupItem && groupItem->groupItem() )
00237         emit groupSelected( groupItem->groupItem() );
00238     else if( targetItem && targetItem->targetItem() ){
00239         kdDebug() << "set active target" << endl;
00240         m_activeTarget = targetItem->targetItem();
00241         emit targetSelected( m_activeTarget );
00242     }
00243 //    else if( fileItem && m_itemToFile.contains(fileItem) )
00244 //  emit fileSelected( m_itemToFile[fileItem] );
00245 }
00246 
00247 void GenericProjectWidget::showDetails( BuildGroupItem * groupItem )
00248 {
00249     m_activeGroup = groupItem;
00250     kdDebug() << "unset active target" << endl;
00251     m_activeTarget = 0;
00252 
00253     m_detailsListView->clear();
00254 
00255     m_targetToItem.clear();
00256     m_fileToItem.clear();
00257 
00258     if( !groupItem )
00259     return;
00260 
00261     QValueList<BuildTargetItem*> targets = groupItem->targets();
00262     QValueListIterator<BuildTargetItem*> it = targets.begin();
00263     while( it != targets.end() ){
00264         GenericTargetListViewItem* createdItem = new GenericTargetListViewItem( m_detailsListView, *it );
00265         m_targetToItem.insert( *it, createdItem );
00266         fillTarget( *it, createdItem );
00267         createdItem->setOpen( true );
00268         ++it;
00269     }
00270 }
00271 
00272 void GenericProjectWidget::fillTarget( BuildTargetItem * target, GenericTargetListViewItem * targetItem )
00273 {
00274     QValueList<BuildFileItem*> files = target->files();
00275     QValueListIterator<BuildFileItem*> it = files.begin();
00276     while( it != files.end() ){
00277     GenericFileListViewItem* createdItem = new GenericFileListViewItem( targetItem, *it );
00278     m_fileToItem.insert( *it, createdItem );
00279     ++it;
00280     }
00281 }
00282 
00283 BuildGroupItem * GenericProjectWidget::activeGroup( )
00284 {
00285     return m_activeGroup;
00286 }
00287 
00288 GenericGroupListViewItem * GenericProjectWidget::addGroup( BuildGroupItem * group )
00289 {
00290     if( !group )
00291         return 0;
00292 
00293     GenericGroupListViewItem* createdItem = 0;
00294     if( group->parentGroup() && m_groupToItem.contains(group->parentGroup()) ){
00295         kdDebug() << "creating GenericGroupListViewItem from parent group" << endl;
00296         createdItem = new GenericGroupListViewItem( m_groupToItem[group->parentGroup()], group );
00297         m_groupToItem.insert( group, createdItem );
00298     } else if( group->parentGroup() ){
00299         kdDebug() << "creating GenericGroupListViewItem from parent group (wo map)" << endl;
00300         addGroup( group->parentGroup() );
00301         createdItem = new GenericGroupListViewItem( m_groupToItem[group->parentGroup()], group );
00302         m_groupToItem.insert( group, createdItem );
00303         m_groupToItem[group->parentGroup()]->setExpandable( true );
00304     } else {
00305         kdDebug() << "creating GenericGroupListViewItem standalone" << endl;
00306         createdItem = new GenericGroupListViewItem( m_overviewListView, group );
00307         m_groupToItem.insert( group, createdItem );
00308     }
00309     return createdItem;
00310 }
00311 
00312 void GenericProjectWidget::addTarget( BuildTargetItem * target )
00313 {
00314     if( !target || !target->parentGroup() || activeGroup() != target->parentGroup() )
00315         return;
00316 
00317     if(  m_groupToItem.contains(target->parentGroup()) ){
00318 //        GenericTargetListViewItem* createdItem = new GenericTargetListViewItem( m_groupToItem[target->parentGroup()], target );
00319         GenericTargetListViewItem* createdItem = new GenericTargetListViewItem( m_detailsListView, target );
00320         m_detailsListView->takeItem(createdItem);
00321         m_targetToItem.insert( target, createdItem );
00322 
00323         showDetails(target->parentGroup());
00324     }
00325 }
00326 
00327 void GenericProjectWidget::addFile( BuildFileItem * file )
00328 {
00329     if( !file || !file->parentTarget() || file->parentTarget()->parentGroup() != activeGroup() )
00330     return;
00331 
00332     if( m_targetToItem.contains(file->parentTarget()) ){
00333     GenericFileListViewItem* createdItem = new GenericFileListViewItem( m_targetToItem[file->parentTarget()], file );
00334     m_fileToItem.insert( file, createdItem );
00335     }
00336 }
00337 
00338 BuildTargetItem * GenericProjectWidget::activeTarget( )
00339 {
00340     return m_activeTarget;
00341 }
00342 
00343 void GenericProjectWidget::showTargetDetails( BuildTargetItem * /*targetItem*/ )
00344 {
00345 }
00346 
00347 void GenericProjectWidget::showFileDetails( BuildFileItem * fileItem )
00348 {
00349     kdDebug() << "GenericProjectWidget::showFileDetails" << endl;
00350     m_part->partController()->editDocument(fileItem->url());
00351 }
00352 
00353 void GenericProjectWidget::initActions( )
00354 {
00355     newGroupAction = new KAction (i18n("New Group"), "group_new", 0,
00356         this, SLOT( slotNewGroup() ), m_part->actionCollection(), "new_group" );
00357     newGroupAction->setToolTip(i18n("New group"));
00358     newGroupAction->setWhatsThis(i18n("<b>New group</b><p>Adds a new group of targets and files. "
00359         "Group is usually a subdirectory in the project directory but that depends on an underlying build system."));
00360     newTargetAction = new KAction (i18n("New Target"), "targetnew_kdevelop", 0,
00361         this, SLOT( slotNewTarget() ), m_part->actionCollection(), "new_target" );
00362     newTargetAction->setToolTip(i18n("New target"));
00363     newTargetAction->setWhatsThis(i18n("<b>New target</b><p>Adds a new target. "
00364         "Target is usually an application, static or shared library but that depends on an underlying build system."));
00365     buildGroupAction = new KAction (i18n("Build Group"), "launch", 0,
00366         this, SLOT( slotBuildGroup() ), m_part->actionCollection(), "build_group" );
00367     buildGroupAction->setToolTip(i18n("Build group"));
00368     buildGroupAction->setWhatsThis(i18n("<b>Build group</b><p>Executes all commands necessary to build the current group."));
00369     buildAction = new KAction (i18n("Build"), "launch", 0,
00370         this, SLOT( slotBuild() ), m_part->actionCollection(), "build" );
00371     buildAction->setToolTip(i18n("Build project"));
00372     buildAction->setWhatsThis(i18n("<b>Build project</b><p>Executes all commands necessary to build the project."));
00373     buildTargetAction = new KAction (i18n("Build Target"), "launch", 0,
00374         this, SLOT( slotBuildTarget() ), m_part->actionCollection(), "build_target" );
00375     buildTargetAction->setToolTip(i18n("Build target"));
00376     buildTargetAction->setWhatsThis(i18n("<b>Build target</b><p>Executes all commands necessary to build the current target."));
00377     buildFileAction = new KAction (i18n("Build File"), "launch", 0,
00378         this, SLOT( slotBuildFile() ), m_part->actionCollection(), "build_file" );
00379     buildFileAction->setToolTip(i18n("Build file"));
00380     buildFileAction->setWhatsThis(i18n("<b>Build file</b><p>Executes all commands necessary to build the current file."));
00381     installGroupAction = new KAction (i18n("Install Group"), 0, 0,
00382         this, SLOT( slotInstallGroup() ), m_part->actionCollection(), "install_group" );
00383     installGroupAction->setToolTip(i18n("Install group"));
00384     installGroupAction->setWhatsThis(i18n("<b>Install group</b><p>Executes all commands necessary to install the current group."));
00385     installAction = new KAction (i18n("Install"), 0, 0,
00386         this, SLOT( slotInstall() ), m_part->actionCollection(), "install" );
00387     installAction->setToolTip(i18n("Install"));
00388     installAction->setWhatsThis(i18n("<b>Install</b><p>Executes all commands necessary to install the project."));
00389     newFileAction = new KAction (i18n("New File"), "filenew", 0,
00390         this, SLOT( slotNewFile() ), m_part->actionCollection(), "new_file" );
00391     newFileAction->setToolTip(i18n("New file"));
00392     newFileAction->setWhatsThis(i18n("<b>New file</b><p>Creates a new file and adds it to a current target."));
00393     addFilesAction = new KAction (i18n("Add Files"), "fileimport", 0,
00394         this, SLOT( slotAddFiles() ), m_part->actionCollection(), "add_files" );
00395     addFilesAction->setToolTip(i18n("Add files"));
00396     addFilesAction->setWhatsThis(i18n("<b>Add files</b><p>Adds existing files to a current target."));
00397     deleteGroupAction = new KAction (i18n("Remove Group"), 0, 0,
00398         this, SLOT( slotDeleteGroup() ), m_part->actionCollection(), "remove_group" );
00399     deleteGroupAction->setToolTip(i18n("Remove group"));
00400     deleteGroupAction->setWhatsThis(i18n("<b>Remove group</b><p>Removes current group."));
00401     deleteTargetAction = new KAction (i18n("Remove Target"), 0, 0,
00402         this, SLOT( slotDeleteTarget() ), m_part->actionCollection(), "remove_target" );
00403     deleteTargetAction->setToolTip(i18n("Remove target"));
00404     deleteTargetAction->setWhatsThis(i18n("<b>Remove target</b><p>Removes current target."));
00405     deleteFileAction = new KAction (i18n("Remove File"), 0, 0,
00406         this, SLOT( slotDeleteFile() ), m_part->actionCollection(), "remove_file" );
00407     deleteFileAction->setToolTip(i18n("Remove file"));
00408     deleteFileAction->setWhatsThis(i18n("<b>Remove file</b><p>Removes current file."));
00409     configureGroupAction = new KAction (i18n("Options..."), "configure", 0,
00410         this, SLOT( slotConfigureGroup() ), m_part->actionCollection(), "configure_group" );
00411     configureGroupAction->setToolTip(i18n("Options"));
00412     configureGroupAction->setWhatsThis(i18n("<b>Options</b><p>Opens a group configuration dialog supplied by a build system plugin."));
00413     configureTargetAction = new KAction (i18n("Options..."), "configure", 0,
00414         this, SLOT( slotConfigureTarget() ), m_part->actionCollection(), "configure_target" );
00415     configureTargetAction->setToolTip(i18n("Options"));
00416     configureTargetAction->setWhatsThis(i18n("<b>Options</b><p>Opens a target configuration dialog supplied by a build system plugin."));
00417     configureFileAction = new KAction (i18n("Options..."), "configure", 0,
00418         this, SLOT( slotConfigureFile() ), m_part->actionCollection(), "configure_item" );
00419     configureFileAction->setToolTip(i18n("Options"));
00420     configureFileAction->setWhatsThis(i18n("<b>Options</b><p>Opens a file configuration dialog supplied by a build system plugin."));
00421     executeAction = new KAction (i18n("Execute"), "exec", 0,
00422         this, SLOT( slotExecute() ), m_part->actionCollection(), "execute" );
00423     executeAction->setToolTip(i18n("Execute project"));
00424     executeAction->setWhatsThis(i18n("<b>Execute project</b><p>Executes the main project executable or the current application target."));
00425     executeGroupAction = new KAction (i18n("Execute"), "exec", 0,
00426         this, SLOT( slotExecuteGroup() ), m_part->actionCollection(), "execute_group" );
00427     executeGroupAction->setToolTip(i18n("Execute group"));
00428     executeGroupAction->setWhatsThis(i18n("<b>Execute group</b><p>Executes the current application target in a group."));
00429     executeTargetAction = new KAction (i18n("Execute"), "exec", 0,
00430         this, SLOT( slotExecuteTarget() ), m_part->actionCollection(), "execute_target" );
00431     executeTargetAction->setToolTip(i18n("Execute target"));
00432     executeTargetAction->setWhatsThis(i18n("<b>Execute target</b><p>Executes application target."));
00433     cleanAction = new KAction (i18n("Clean"), 0, 0,
00434         this, SLOT( slotClean() ), m_part->actionCollection(), "clean" );
00435     cleanAction->setToolTip(i18n("Clean project"));
00436     cleanAction->setWhatsThis(i18n("<b>Clean project</b><p>Executes all commands necessary to clean the project."));
00437     cleanGroupAction = new KAction (i18n("Clean"), 0, 0,
00438         this, SLOT( slotCleanGroup() ), m_part->actionCollection(), "clean_group" );
00439     cleanGroupAction->setToolTip(i18n("Clean group"));
00440     cleanGroupAction->setWhatsThis(i18n("<b>Clean group</b><p>Executes all commands necessary to clean the current group."));
00441     cleanTargetAction = new KAction (i18n("Clean"), 0, 0,
00442         this, SLOT( slotCleanTarget() ), m_part->actionCollection(), "clean_target" );
00443     cleanTargetAction->setToolTip(i18n("Clean target"));
00444     cleanTargetAction->setWhatsThis(i18n("<b>Clean target</b><p>Executes all commands necessary to clean the current target."));
00445 
00446 }
00447 
00448 void GenericProjectWidget::showGroupContextMenu( KListView * l, QListViewItem * i, const QPoint & p )
00449 {
00450     if (( !l ) || (!i) )
00451         return ;
00452 
00453     KPopupMenu popup( this );
00454     popup.insertTitle(i18n( "Group: %1" ).arg( i->text( 0 ) ));
00455     configureGroupAction->plug(&popup);
00456     popup.insertSeparator();
00457     newGroupAction->plug(&popup);
00458     newTargetAction->plug(&popup);
00459     popup.insertSeparator();
00460     deleteGroupAction->plug(&popup);
00461     popup.insertSeparator();
00462     buildGroupAction->plug(&popup);
00463     cleanGroupAction->plug(&popup);
00464     executeGroupAction->plug(&popup);
00465 
00466     popup.exec(p);
00467 }
00468 
00469 void GenericProjectWidget::showDetailContextMenu( KListView * l, QListViewItem * i, const QPoint & p )
00470 {
00471     if (( !l ) || (!i) )
00472         return ;
00473 
00474     GenericTargetListViewItem *t = dynamic_cast<GenericTargetListViewItem*>(i);
00475     GenericFileListViewItem *f = dynamic_cast<GenericFileListViewItem*>(i);
00476 
00477     if (t)
00478     {
00479         KPopupMenu popup( this );
00480     popup.insertTitle(i18n( "Target: %1" ).arg( t->text( 0 ) ));
00481 
00482         configureTargetAction->plug(&popup);
00483         popup.insertSeparator();
00484         newFileAction->plug(&popup);
00485         addFilesAction->plug(&popup);
00486         popup.insertSeparator();
00487         deleteTargetAction->plug(&popup);
00488         popup.insertSeparator();
00489         buildTargetAction->plug(&popup);
00490         cleanTargetAction->plug(&popup);
00491         executeTargetAction->plug(&popup);
00492 
00493         popup.exec(p);
00494     }
00495     if (f)
00496     {
00497         KPopupMenu popup( this );
00498     popup.insertTitle(i18n( "File: %1" ).arg( f->text( 0 ) ));
00499 
00500         configureFileAction->plug(&popup);
00501         popup.insertSeparator();
00502         deleteFileAction->plug(&popup);
00503 
00504         popup.exec(p);
00505     }
00506 }
00507 
00508 
00509 
00510 //Important slot definitions:
00511 
00512 void GenericProjectWidget::slotNewGroup( )
00513 {
00514     if (!m_overviewListView->currentItem())
00515         return;
00516     GenericGroupListViewItem *git = dynamic_cast<GenericGroupListViewItem *>(m_overviewListView->currentItem());
00517     if (!git)
00518         return;
00519     bool ok;
00520     QString groupName = KInputDialog::getText(i18n("Group Name"), i18n("Enter the group name:"), "", &ok, this );
00521     if (!ok)
00522         return;
00523     QDir dir;
00524     if (!dir.mkdir( QDir::cleanDirPath(m_part->projectDirectory() + "/" + git->groupItem()->path() + "/" + groupName)) )
00525         return;
00526     BuildGroupItem *bit = new BuildGroupItem(groupName, git->groupItem());
00527     addGroup(bit);
00528 }
00529 
00530 void GenericProjectWidget::slotNewTarget( )
00531 {
00532     if (!m_overviewListView->currentItem())
00533         return;
00534     GenericGroupListViewItem *git = dynamic_cast<GenericGroupListViewItem *>(m_overviewListView->currentItem());
00535     if (!git)
00536         return;
00537     bool ok;
00538     QString targetName = KInputDialog::getText(i18n("Target Name"), i18n("Enter the target name:"), "", &ok, this );
00539     if (!ok)
00540         return;
00541     BuildTargetItem *tit = new BuildTargetItem(targetName, git->groupItem());
00542     addTarget(tit);
00543 }
00544 
00545 void GenericProjectWidget::slotBuild( )
00546 {
00547     m_part->buildSystem()->build();
00548 }
00549 
00550 void GenericProjectWidget::slotBuildGroup( )
00551 {
00552     if (!m_overviewListView->currentItem())
00553         return;
00554     GenericGroupListViewItem *git = dynamic_cast<GenericGroupListViewItem *>(m_overviewListView->currentItem());
00555     if (!git)
00556         return;
00557     m_part->buildSystem()->build(git->groupItem());
00558 }
00559 
00560 void GenericProjectWidget::slotBuildTarget( )
00561 {
00562     if (!m_detailsListView->currentItem())
00563         return;
00564     GenericTargetListViewItem *tit = dynamic_cast<GenericTargetListViewItem *>(m_detailsListView->currentItem());
00565     if (!tit)
00566         return;
00567     m_part->buildSystem()->build(tit->targetItem());
00568 }
00569 
00570 void GenericProjectWidget::slotBuildFile( )
00571 {
00572     if (!m_detailsListView->currentItem())
00573         return;
00574     GenericFileListViewItem *fit = dynamic_cast<GenericFileListViewItem *>(m_detailsListView->currentItem());
00575     if (!fit)
00576         return;
00577     m_part->buildSystem()->build(fit->fileItem());
00578 }
00579 
00580 void GenericProjectWidget::slotInstall( )
00581 {
00582     m_part->buildSystem()->install();
00583 }
00584 
00585 void GenericProjectWidget::slotInstallGroup( )
00586 {
00587     if (!m_overviewListView->currentItem())
00588         return;
00589     GenericGroupListViewItem *git = dynamic_cast<GenericGroupListViewItem *>(m_overviewListView->currentItem());
00590     if (!git)
00591         return;
00592     m_part->buildSystem()->install(git->groupItem());
00593 }
00594 
00595 void GenericProjectWidget::slotInstallTarget( )
00596 {
00597     if (!m_detailsListView->currentItem())
00598         return;
00599     GenericTargetListViewItem *tit = dynamic_cast<GenericTargetListViewItem *>(m_detailsListView->currentItem());
00600     if (!tit)
00601         return;
00602     m_part->buildSystem()->install(tit->targetItem());
00603 }
00604 
00605 void GenericProjectWidget::slotExecute( )
00606 {
00607     m_part->buildSystem()->execute();
00608 }
00609 
00610 void GenericProjectWidget::slotExecuteGroup( )
00611 {
00612     if (!m_overviewListView->currentItem())
00613         return;
00614     GenericGroupListViewItem *git = dynamic_cast<GenericGroupListViewItem *>(m_overviewListView->currentItem());
00615     if (!git)
00616         return;
00617     m_part->buildSystem()->execute(git->groupItem());
00618 }
00619 
00620 void GenericProjectWidget::slotExecuteTarget( )
00621 {
00622     if (!m_detailsListView->currentItem())
00623         return;
00624     GenericTargetListViewItem *tit = dynamic_cast<GenericTargetListViewItem *>(m_detailsListView->currentItem());
00625     if (!tit)
00626         return;
00627     m_part->buildSystem()->execute(tit->targetItem());
00628 }
00629 
00630 void GenericProjectWidget::slotNewFile( )
00631 {
00632     if (!m_detailsListView->currentItem())
00633         return;
00634     GenericTargetListViewItem *tit = dynamic_cast<GenericTargetListViewItem *>(m_detailsListView->currentItem());
00635     if (!tit)
00636         return;
00637 
00638     KDevCreateFile * createFileSupport = m_part->createFileSupport();
00639     if (createFileSupport)
00640     {
00641         kdDebug() << "GenericProjectWidget::slotNewFile " << tit->targetItem()->parentGroup()->name() << endl;
00642         KDevCreateFile::CreatedFile crFile =
00643             createFileSupport->createNewFile(QString::null, QDir::cleanDirPath(m_part->projectDirectory() + "/" + tit->targetItem()->parentGroup()->path()));
00644         kdDebug() << "status for " << QDir::cleanDirPath(m_part->projectDirectory() + "/" + tit->targetItem()->parentGroup()->path()) << " is " << crFile.status << endl;
00645 //        KURL url;
00646 //        url.setPath(QDir::cleanDirPath(crFile.dir + "/" + crFile.filename));
00647 //        BuildFileItem *fit = new BuildFileItem(url, tit->targetItem());
00648 //        addFile(fit);
00649     }
00650 }
00651 
00652 void GenericProjectWidget::slotAddFiles( )
00653 {
00654     QString startDir = m_part->projectDirectory();
00655     if (activeTarget())
00656         startDir += "/" + activeTarget()->path();
00657     else if (activeGroup())
00658         startDir += "/" + activeGroup()->path();
00659 
00660     QStringList fileList = KFileDialog::getOpenFileNames( startDir );
00661     if( fileList.isEmpty() )
00662     return;
00663 
00664     QStringList lst;
00665     for( QStringList::Iterator it=fileList.begin(); it!=fileList.end(); ++it )
00666     {
00667     QString absFileName = *it;
00668     if( !absFileName.startsWith(m_part->projectDirectory()) )
00669         continue;
00670 
00671     lst << absFileName.mid( m_part->projectDirectory().length() + 1 );
00672     }
00673 
00674     m_part->addFiles( lst );
00675 }
00676 
00677 void GenericProjectWidget::slotDeleteGroup( )
00678 {
00679     if (!m_overviewListView->currentItem())
00680         return;
00681     GenericGroupListViewItem *git = dynamic_cast<GenericGroupListViewItem *>(m_overviewListView->currentItem());
00682     if (!git)
00683         return;
00684 
00685     RemoveSubprojectDialog dia(i18n("Remove Group"), i18n("Remove group?"), this);
00686     if (dia.exec() == QDialog::Accepted)
00687     {
00688         if (dia.removeFromDisk())
00689         {
00690             QDir d;
00691             d.rmdir( QDir::cleanDirPath(m_part->projectDirectory() + "/" + git->groupItem()->path()));
00692         }
00693         takeGroup(git);
00694     }
00695 }
00696 
00697 void GenericProjectWidget::slotDeleteTarget( )
00698 {
00699     if (!m_detailsListView->currentItem())
00700         return;
00701     GenericTargetListViewItem *tit = dynamic_cast<GenericTargetListViewItem *>(m_detailsListView->currentItem());
00702     if (!tit)
00703         return;
00704 
00705     if (KMessageBox::questionYesNo(this, i18n("Remove target?")) == KMessageBox::Yes)
00706     {
00707         takeTarget(tit);
00708     }
00709 }
00710 
00711 void GenericProjectWidget::slotDeleteFile( )
00712 {
00713     if (!m_detailsListView->currentItem())
00714         return;
00715     GenericFileListViewItem *fit = dynamic_cast<GenericFileListViewItem *>(m_detailsListView->currentItem());
00716     if (!fit)
00717         return;
00718 
00719     RemoveSubprojectDialog dia(i18n("Remove File"), i18n("Remove file?"), this);
00720     if (dia.exec() == QDialog::Accepted)
00721     {
00722         if (dia.removeFromDisk())
00723         {
00724             kdDebug() << "GenericProjectWidget::slotDeleteFile " << fit->fileItem()->url().url() << endl;
00725             KIO::NetAccess::del(fit->fileItem()->url(), (QWidget*)0);
00726         }
00727         takeFile(fit);
00728     }
00729 }
00730 
00731 void GenericProjectWidget::slotConfigureGroup( )
00732 {
00733     kdDebug() << "GenericProjectWidget::slotConfigureGroup 1" << endl;
00734     if (!m_overviewListView->currentItem())
00735         return;
00736     kdDebug() << "GenericProjectWidget::slotConfigureGroup 2" << endl;
00737     GenericGroupListViewItem *git = dynamic_cast<GenericGroupListViewItem *>(m_overviewListView->currentItem());
00738     if (!git)
00739         return;
00740     kdDebug() << "GenericProjectWidget::slotConfigureGroup 3" << endl;
00741 
00742     KDialogBase *dia = new KDialogBase(KDialogBase::Tabbed, i18n("Group Options"),
00743         KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, this);
00744     kdDebug() << "GenericProjectWidget::slotConfigureGroup 4" << endl;
00745 
00746     m_part->buildSystem()->configureBuildItem(dia, git->buildItem());
00747     kdDebug() << "GenericProjectWidget::slotConfigureGroup 5" << endl;
00748 }
00749 
00750 void GenericProjectWidget::slotConfigureTarget( )
00751 {
00752     if (!m_detailsListView->currentItem())
00753         return;
00754     GenericTargetListViewItem *tit = dynamic_cast<GenericTargetListViewItem *>(m_detailsListView->currentItem());
00755     if (!tit)
00756         return;
00757 
00758     KDialogBase *dia = new KDialogBase(KDialogBase::Tabbed, i18n("Target Options"),
00759         KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, this);
00760 
00761     m_part->buildSystem()->configureBuildItem(dia, tit->buildItem());
00762 }
00763 
00764 void GenericProjectWidget::slotConfigureFile( )
00765 {
00766     if (!m_detailsListView->currentItem())
00767         return;
00768     GenericFileListViewItem *fit = dynamic_cast<GenericFileListViewItem *>(m_detailsListView->currentItem());
00769     if (!fit)
00770         return;
00771 
00772     KDialogBase *dia = new KDialogBase(KDialogBase::Tabbed, i18n("File Options"),
00773         KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, this);
00774 
00775     m_part->buildSystem()->configureBuildItem(dia, fit->buildItem());
00776 }
00777 
00778 void GenericProjectWidget::slotClean( )
00779 {
00780     m_part->buildSystem()->clean();
00781 }
00782 
00783 void GenericProjectWidget::slotCleanGroup( )
00784 {
00785     if (!m_overviewListView->currentItem())
00786         return;
00787     GenericGroupListViewItem *git = dynamic_cast<GenericGroupListViewItem *>(m_overviewListView->currentItem());
00788     if (!git)
00789         return;
00790     m_part->buildSystem()->clean(git->groupItem());
00791 }
00792 
00793 void GenericProjectWidget::slotCleanTarget( )
00794 {
00795     if (!m_detailsListView->currentItem())
00796         return;
00797     GenericTargetListViewItem *tit = dynamic_cast<GenericTargetListViewItem *>(m_detailsListView->currentItem());
00798     if (!tit)
00799         return;
00800     m_part->buildSystem()->clean(tit->targetItem());
00801 }
00802 
00803 
00804 void GenericProjectWidget::takeGroup( GenericGroupListViewItem * it )
00805 {
00806     //@todo adymo: allow to remove nested subdirs
00807     BuildGroupItem *group = it->groupItem();
00808     if (group->groups().count() == 0)
00809     {
00810         m_groupToItem.remove( group );
00811         delete group;
00812         delete it;
00813     }
00814 }
00815 
00816 void GenericProjectWidget::takeTarget( GenericTargetListViewItem * item )
00817 {
00818     kdDebug() << "============> takeTarget" << endl;
00819 
00820     BuildTargetItem *target = item->targetItem();
00821     if( !target ){
00822     kdDebug() << "============> no target!!!!!" << endl;
00823     return;
00824     }
00825 
00826     QStringList fileList;
00827     QValueList<BuildFileItem*> files = target->files();
00828     for( QValueList<BuildFileItem*>::Iterator it=files.begin(); it!=files.end(); ++ it )
00829     {
00830     QString path = (*it)->url().path();
00831     kdDebug() << "============> remove: " << path << endl;
00832     if( !path.startsWith(m_part->projectDirectory()) )
00833         continue;
00834 
00835     fileList << path.mid( m_part->projectDirectory().length() + 1 );
00836     }
00837 
00838     delete item;
00839     m_targetToItem.remove( target );
00840     delete target;
00841 
00842     kdDebug() << "===========> remove files: " << fileList.join( ", " );
00843 }
00844 
00845 void GenericProjectWidget::takeFile( GenericFileListViewItem * it )
00846 {
00847     BuildFileItem *file = it->fileItem();
00848     m_fileToItem.remove( file );
00849     delete file;
00850     delete it;
00851 }
00852 
00853 void GenericProjectWidget::slotItemExecuted( QListViewItem * item )
00854 {
00855     GenericGroupListViewItem* groupItem = dynamic_cast<GenericGroupListViewItem*>( item );
00856     GenericTargetListViewItem* targetItem = dynamic_cast<GenericTargetListViewItem*>( item );
00857     GenericFileListViewItem* fileItem = dynamic_cast<GenericFileListViewItem*>( item );
00858 
00859     if( groupItem && groupItem->groupItem() )
00860         emit groupExecuted( groupItem->groupItem() );
00861     else if( targetItem && targetItem->targetItem() ){
00862         kdDebug() << "set active target while execute" << endl;
00863         m_activeTarget = targetItem->targetItem();
00864         emit targetExecuted( m_activeTarget );
00865     }
00866     else if( fileItem )
00867     {
00868         kdDebug() << "emit fileExecuted()" << endl;
00869         emit fileExecuted( fileItem->fileItem() );
00870     }
00871 }
00872 
00873 void GenericProjectWidget::slotDeleteTargetOrFile( )
00874 {
00875     QListViewItem * item = m_detailsListView->currentItem();
00876     if (!item)
00877         return;
00878     GenericTargetListViewItem* targetItem = dynamic_cast<GenericTargetListViewItem*>( item );
00879     GenericFileListViewItem* fileItem = dynamic_cast<GenericFileListViewItem*>( item );
00880     if (targetItem)
00881         slotDeleteTarget();
00882     else if (fileItem)
00883         slotDeleteFile();
00884 }
00885 
00886 void GenericProjectWidget::slotConfigureTargetOrFile( )
00887 {
00888     QListViewItem * item = m_detailsListView->currentItem();
00889     if (!item)
00890         return;
00891     GenericTargetListViewItem* targetItem = dynamic_cast<GenericTargetListViewItem*>( item );
00892     GenericFileListViewItem* fileItem = dynamic_cast<GenericFileListViewItem*>( item );
00893     if (targetItem)
00894         slotConfigureTarget();
00895     else if (fileItem)
00896         slotConfigureFile();
00897 }
00898 
00899 #include "genericproject_widget.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:22 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003