KDevelop API Documentation

choosetargetdialog.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                              -------------------
00003     begin                : 29.11.2002
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 
00017 #include <qcheckbox.h>
00018 #include <qgroupbox.h>
00019 #include <qlistview.h>
00020 #include <qptrlist.h>
00021 #include <qradiobutton.h>
00022 #include <qstringlist.h>
00023 #include <qfileinfo.h>
00024 
00025 #include <kcombobox.h>
00026 #include <kdebug.h>
00027 #include <klistbox.h>
00028 #include <kmessagebox.h>
00029 #include <kprocess.h>
00030 #include <ksqueezedtextlabel.h>
00031 #include <kurl.h>
00032 
00033 #include "choosetargetdialog.h"
00034 
00035 #include "autodetailsview.h"
00036 #include "autolistviewitems.h"
00037 #include "autosubprojectview.h"
00038 
00039 #include "misc.h"
00040 #include "autoprojectwidget.h"
00041 #include "autoprojectpart.h"
00042 
00043 #include "kdevpartcontroller.h"
00044 
00045 
00046 ChooseTargetDialog::ChooseTargetDialog ( AutoProjectWidget* widget, AutoProjectPart* part, QStringList fileList, QWidget* parent, const char* name )
00047   : ChooseTargetDlgBase ( parent, name, false, 0 ), m_choosenSubproject ( 0 ), m_choosenTarget ( 0 )
00048 {
00049     m_widget = widget;
00050     m_part = part;
00051     m_fileList = fileList;
00052     m_subprojectList = widget->allSubprojectItems();
00053 
00054     subprojectComboBox->setAutoCompletion ( true );
00055     targetComboBox->setAutoCompletion ( true );
00056 
00057     setIcon ( SmallIcon ( "target_kdevelop" ) );
00058     /*QStringList historyList;*/
00059 
00060     SubprojectItem* spitem = m_subprojectList.first();
00061 
00062     for ( ; spitem; spitem = m_subprojectList.next() )
00063     {
00064         QPtrList <TargetItem> targetList = spitem->targets;
00065         TargetItem* titem = targetList.first();
00066 
00067         // Only insert Subproject which have a "regular" target
00068         for ( ; titem; titem = targetList.next() )
00069         {
00070             if ( titem->primary == "PROGRAMS" || titem->primary == "LIBRARIES" ||
00071                     titem->primary == "LTLIBRARIES" || titem->primary == "JAVA" )
00072             {
00073                 subprojectComboBox->insertItem ( SmallIcon ( "folder" ), spitem->subdir );
00074 
00075                 //historyList.append ( spitem->subdir );
00076                 //subprojectComboBox->addToHistory ( spitem->subdir );
00077 
00078                 break;
00079             }
00080         }
00081     }
00082 
00083     //subprojectComboBox->setHistoryItems ( historyList, true );
00084 
00085     if ( widget->activeTarget() && widget->activeSubproject() )
00086     {
00087         m_choosenTarget = widget->activeTarget();
00088         //kdDebug ( 9000 ) << "1) Choosen target is " << m_choosenTarget->name << endl;
00089         m_choosenSubproject = widget->activeSubproject();
00090         choosenTargetLabel->setText ( ( widget->activeSubproject()->path + "/<b>" + m_widget->activeTarget()->name + "</b>" ).mid ( m_part->projectDirectory().length() + 1 ) );
00091         subprojectComboBox->setEnabled ( false );
00092         targetComboBox->setEnabled ( false );
00093 
00094         subprojectComboBox->setCurrentItem ( widget->activeSubproject()->subdir );
00095         slotSubprojectChanged ( widget->activeSubproject()->subdir );
00096     }
00097     else
00098     {
00099         activeTargetRadioButton->setChecked ( false );
00100         chooseTargetRadioButton->setChecked ( true );
00101         activeTargetRadioButton->setEnabled ( false );
00102         neverAskAgainCheckBox->setEnabled ( false );
00103 
00104         slotSubprojectChanged ( subprojectComboBox->text(0) );
00105     }
00106 
00107     QStringList::iterator it;
00108     QString fileName;
00109 
00110     for ( it = fileList.begin(); it != fileList.end(); ++it )
00111     {
00112         int pos = ( *it ).findRev('/');
00113         if (pos != -1)
00114         {
00115             fileName = ( *it ).mid(pos+1);
00116         }
00117         else
00118         {
00119             fileName = ( *it );
00120         }
00121 
00122         newFilesListBox->insertItem ( SmallIcon ( "document" ), fileName );
00123     }
00124 
00125     connect ( activeTargetRadioButton, SIGNAL ( toggled ( bool ) ), this, SLOT ( slotActiveTargetToggled ( bool ) ) );
00126     connect ( chooseTargetRadioButton, SIGNAL ( toggled ( bool ) ), this, SLOT ( slotChooseTargetToggled ( bool ) ) );
00127 
00128     connect ( subprojectComboBox, SIGNAL ( activated ( const QString& ) ), this, SLOT ( slotSubprojectChanged ( const QString& ) ) );
00129     connect ( targetComboBox, SIGNAL ( activated ( const QString& ) ), this, SLOT ( slotTargetChanged ( const QString& ) ) );
00130 }
00131 
00132 
00133 ChooseTargetDialog::~ChooseTargetDialog()
00134 {
00135 }
00136 
00137 void ChooseTargetDialog::slotSubprojectChanged ( const QString& name )
00138 {
00139     m_choosenTarget = 0;
00140     SubprojectItem* spitem = m_subprojectList.first();
00141 
00142     for ( ; spitem; spitem = m_subprojectList.next() )
00143     {
00144         if ( spitem->subdir == name )
00145         {
00146             QPtrList <TargetItem> targetList = spitem->targets;
00147             TargetItem* titem = targetList.first();
00148 
00149             targetComboBox->clear();
00150 
00151 /*          choosenSubprojectLabel->setText ( ( spitem->path + "<b>" + ->name + "</b>" ).mid ( m_widget->projectDirectory().length() + 1 ) );*/
00152 
00153             m_choosenSubproject = spitem;
00154 
00155             for ( ; titem; titem = targetList.next() )
00156             {
00157                 if ( titem->primary == "PROGRAMS" || titem->primary == "LIBRARIES" ||
00158                         titem->primary == "LTLIBRARIES" || titem->primary == "JAVA" )
00159                 {
00160                     targetComboBox->insertItem ( SmallIcon ( "target_kdevelop" ), titem->name );
00161 
00162                     //targetComboBox->addToHistory ( titem->name );
00163 
00164                     // if the Active Target is in the currently selected Subproject
00165                     if ( m_widget->activeTarget() &&
00166                         titem->name == m_widget->activeTarget()->name )
00167                     {
00168                         targetComboBox->setCurrentItem ( titem->name );
00169                         choosenTargetLabel->setText ( ( spitem->path + "/<b>" + titem->name + "</b>" ).mid ( m_part->projectDirectory().length() + 1 ) );
00170                         //choosenSubprojectLabel->setText ( ( spitem->path + "<b>" + titem->name + "</b>" ).mid ( m_widget->projectDirectory().length() + 1 ) );
00171                         m_choosenTarget = titem;
00172                         //kdDebug ( 9000 ) << "2) Choosen target is " << m_choosenTarget->name << endl;
00173                     }
00174                     else
00175                     {
00176                         //targetComboBox->setCurrentItem ( 0 );
00177                         if ( !m_choosenTarget )
00178                         {
00179                             choosenTargetLabel->setText ( ( spitem->path + "/<b>" + titem->name + "</b>" ).mid ( m_part->projectDirectory().length() + 1 ) );
00180                             //choosenSubprojectLabel->setText ( ( spitem->path + "<b>" + titem->name + "</b>" ).mid ( m_widget->projectDirectory().length() + 1 ) );
00181 
00182                             m_choosenTarget = titem;
00183                         }
00184                         //kdDebug ( 9000 ) << "2a) Choosen target is " << m_choosenTarget->name << endl;
00185                     }
00186                 }
00187             }
00188 
00189             break;
00190         }
00191     }
00192 }
00193 
00194 void ChooseTargetDialog::slotTargetChanged ( const QString& name )
00195 {
00196     choosenTargetLabel->setText ( ( m_choosenSubproject->path + "/<b>" + name + "</b>" ).mid ( m_part->projectDirectory().length() + 1 ) );
00197 
00198     QPtrList <TargetItem> targetList = m_choosenSubproject->targets;
00199     TargetItem* titem = targetList.first();
00200 
00201     for ( ; titem; titem = targetList.next() )
00202     {
00203         if ( titem->name == name )
00204         {
00205             m_choosenTarget = titem;
00206             //kdDebug ( 9000 ) << "4) Choosen target is " << m_choosenTarget->name << endl;
00207 
00208             break;
00209         }
00210     }
00211 }
00212 
00213 void ChooseTargetDialog::slotActiveTargetToggled(bool on)
00214 {
00215     if ( on )
00216     {
00217         chooseTargetRadioButton->setChecked ( false );
00218 /*      choosenTargetGroupBox->setEnabled ( false );*/
00219         subprojectComboBox->setEnabled ( false );
00220         targetComboBox->setEnabled ( false );
00221     }
00222     else
00223     {
00224         chooseTargetRadioButton->setChecked ( true );
00225 /*      choosenTargetGroupBox->setEnabled ( true );*/
00226         subprojectComboBox->setEnabled ( true );
00227         targetComboBox->setEnabled ( true );
00228     }
00229 }
00230 
00231 void ChooseTargetDialog::slotChooseTargetToggled(bool on)
00232 {
00233     if ( on )
00234     {
00235         activeTargetRadioButton->setChecked ( false );
00236 /*      choosenTargetGroupBox->setEnabled ( true );*/
00237         subprojectComboBox->setEnabled ( true );
00238         targetComboBox->setEnabled ( true );
00239     }
00240     else
00241     {
00242         activeTargetRadioButton->setChecked ( true );
00243 /*      choosenTargetGroupBox->setEnabled ( false );*/
00244         subprojectComboBox->setEnabled ( false );
00245         targetComboBox->setEnabled ( false );
00246     }
00247 }
00248 
00249 void ChooseTargetDialog::accept ()
00250 {
00251     if ( activeTargetRadioButton->isChecked() )
00252     {
00253         m_choosenTarget = m_widget->activeTarget();
00254         m_choosenSubproject = m_widget->activeSubproject();
00255     }
00256     if ( !m_choosenSubproject || !m_choosenTarget )
00257         return;
00258 
00259     //kdDebug ( 9000 ) << "3) Choosen target is " << m_choosenTarget->name << endl;
00260 
00261     QStringList newFileList;
00262     QStringList::iterator it;
00263     QString directory, fileName;
00264 
00265     for ( it = m_fileList.begin(); it != m_fileList.end(); ++it )
00266     {
00267         bool found = false;
00268 
00269         int pos = ( *it ).findRev('/');
00270         if (pos != -1)
00271         {
00272             directory = ( *it ).left(pos);
00273             fileName = ( *it ).mid(pos+1);
00274         }
00275         else
00276         {
00277             fileName = ( *it );
00278         }
00279 
00280         FileItem * fitem = m_choosenTarget->sources.first();
00281         for ( ; fitem; fitem = m_choosenTarget->sources.next() )
00282         {
00283             if ( fitem->name == fileName )
00284             {
00285                 KMessageBox::error ( this, i18n ( "The file %1 already exists in the chosen target.\nThe file will be created but will not be added to the target.\n"
00286                                                                 "Rename the file and select 'Add Existing Files' from the Automake Manager." ).arg ( fitem->name ),
00287                                                                 i18n ( "Error While Adding Files" ) );
00288                 found = true;
00289             }
00290         }
00291 
00292         if ( !found )
00293         {
00296             if (AutoProjectPrivate::isHeader(fileName) &&
00297                 ( m_choosenTarget->primary == "PROGRAMS" || m_choosenTarget->primary == "LIBRARIES" ||  m_choosenTarget->primary == "LTLIBRARIES" ) )
00298             {
00299                 kdDebug ( 9020 ) << "Ignoring header file and adding it to noinst_HEADERS: " << fileName << endl;
00300                 TargetItem* noinst_HEADERS_item = m_widget->getSubprojectView()->findNoinstHeaders(m_choosenSubproject);
00301                 FileItem *fitem = m_widget->createFileItem( fileName, m_choosenSubproject );
00302                 noinst_HEADERS_item->sources.append( fitem );
00303                 noinst_HEADERS_item->insertItem( fitem );
00304 
00305                 QString varname = "noinst_HEADERS";
00306                 m_choosenSubproject->variables[ varname ] += ( " " + fileName );
00307 
00308                 QMap<QString, QString> replaceMap;
00309                 replaceMap.insert( varname, m_choosenSubproject->variables[ varname ] );
00310 
00311                 AutoProjectTool::modifyMakefileam( m_choosenSubproject->path + "/Makefile.am", replaceMap );
00312             }
00313             else
00314             {
00315                 fitem = m_widget->createFileItem( fileName,m_choosenSubproject );
00316                 m_choosenTarget->sources.append( fitem );
00317                 m_choosenTarget->insertItem( fitem );
00318 
00319                 QString canontargetname = AutoProjectTool::canonicalize( m_choosenTarget->name );
00320                 QString varname = canontargetname + "_SOURCES";
00321                 m_choosenSubproject->variables[ varname ] += ( " " + fileName );
00322 
00323                 QMap<QString, QString> replaceMap;
00324                 replaceMap.insert( varname, m_choosenSubproject->variables[ varname ] );
00325 
00326                 AutoProjectTool::modifyMakefileam( m_choosenSubproject->path + "/Makefile.am", replaceMap );
00327             }
00328             newFileList.append ( m_choosenSubproject->path.mid ( m_part->projectDirectory().length() + 1 ) + "/" + fileName );
00329         }
00330 
00331         if ( directory.isEmpty() || directory != m_choosenSubproject->subdir )
00332         {
00333             KShellProcess proc("/bin/sh");
00334 
00335             proc << "mv";
00336             proc << KShellProcess::quote( m_part->projectDirectory() + "/" + directory + "/" + fileName );
00337             proc << KShellProcess::quote( m_choosenSubproject->path + "/" + fileName );
00338             proc.start(KProcess::DontCare);
00339         }
00340 
00341         // why open the files?!
00342 //      m_part->partController()->editDocument ( KURL ( m_choosenSubproject->path + "/" + fileName ) );
00343 
00344         found = false;
00345     }
00346 
00347     m_widget->emitAddedFiles( newFileList );
00348 
00349     QDialog::accept();
00350 }
00351 
00352 TargetItem* ChooseTargetDialog::choosenTarget()
00353 {
00354     return m_choosenTarget;
00355 }
00356 
00357 SubprojectItem* ChooseTargetDialog::choosenSubproject()
00358 {
00359     return m_choosenSubproject;
00360 }
00361 
00362 void ChooseTargetDialog::slotSubprojectTextChanged ( const QString& text )
00363 {
00364     Q_UNUSED( text );
00365     //KCompletionBox box = subprojectComboBox->
00366 }
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:39 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003