projectdlgs.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2005 by David Saxton                                    *
00003  *   david@bluehaze.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include "createsubprojectwidget.h"
00012 #include "linkeroptionswidget.h"
00013 #include "microlibrary.h"
00014 #include "microselectwidget.h"
00015 #include "newprojectwidget.h"
00016 #include "processingoptionswidget.h"
00017 #include "projectdlgs.h"
00018 #include "projectmanager.h"
00019 
00020 #include <cassert>
00021 #include <kcombobox.h>
00022 #include <kdeversion.h>
00023 #include <kfiledialog.h>
00024 #include <klineedit.h>
00025 #include <klocale.h>
00026 #include <kurlrequester.h>
00027 #include <qcheckbox.h>
00028 #include <qcombobox.h>
00029 #include <qlabel.h>
00030 #include <qlayout.h>
00031 
00032 //BEGIN class NewProjectDlg
00033 NewProjectDlg::NewProjectDlg( QWidget * parent )
00034         : KDialogBase( parent, "newprojectdlg", true, "New Project", KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true )
00035 {
00036         m_pWidget = new NewProjectWidget(this);
00037         connect( m_pWidget->projectNameEdit, SIGNAL(textChanged(const QString & )), this, SLOT(locationChanged(const QString& )) );
00038         connect( m_pWidget->projectLocationURL, SIGNAL(textChanged(const QString & )), this, SLOT(locationChanged(const QString& )) );
00039     
00040     // Check if already valid dir
00041         locationChanged( QString::null );
00042     
00043         m_pWidget->projectLocationURL->setURL( QDir::homeDirPath() );
00044         m_pWidget->projectLocationURL->setMode( KFile::Directory );
00045     
00046         setMainWidget( m_pWidget );
00047         setInitialSize( m_pWidget->rect().size() );
00048 }
00049 
00050 void NewProjectDlg::accept()
00051 {
00052         hide();
00053 
00054         m_bAccepted = true;
00055 
00056         m_projectName = m_pWidget->projectNameEdit->text();
00057         m_projectLocation = m_pWidget->projectLocationURL->url();
00058 }
00059 
00060 void NewProjectDlg::reject()
00061 {
00062         m_bAccepted = false;
00063 }
00064 
00065 void NewProjectDlg::locationChanged( const QString & )
00066 {
00067         m_location = m_pWidget->projectLocationURL->url();
00068         QDir subDir(m_location);
00069     
00070         if ( !m_location.endsWith("/") )
00071                 m_location.append("/");
00072     
00073         if ( !m_pWidget->projectNameEdit->text().isEmpty() )
00074                 m_location.append( m_pWidget->projectNameEdit->text().lower() + "/" );
00075     
00076         m_pWidget->locationLabel->setText( m_location );
00077     
00078         QDir dir(m_location);
00079         
00080         if ( dir.exists() || !subDir.exists() ) 
00081                 enableButtonOK(false);
00082         
00083         else
00084                 enableButtonOK(true);
00085 }
00086 //END class NewProjectDlg
00087 
00088 
00089 
00090 //BEGIN class CreateSubprojectDlg
00091 CreateSubprojectDlg::CreateSubprojectDlg( QWidget * parent )
00092         : KDialogBase( parent, "Create Subproject Dialog", true, "Create Subproject", KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true )
00093 {
00094         m_pWidget = new CreateSubprojectWidget(this);
00095         
00096         if ( ProjectManager::self()->currentProject() )
00097                 m_pWidget->m_targetFile->setURL( ProjectManager::self()->currentProject()->directory() );
00098         
00099         m_type = ProgramType;
00100     
00101         setMainWidget( m_pWidget );
00102         setInitialSize( m_pWidget->rect().size() );
00103 }
00104 
00105 
00106 CreateSubprojectDlg::~CreateSubprojectDlg()
00107 {
00108 }
00109 
00110 
00111 void CreateSubprojectDlg::accept()
00112 {
00113         hide();
00114 
00115         m_bAccepted = true;
00116 
00117         m_targetFile = m_pWidget->m_targetFile->url();
00118         m_type = (Type)m_pWidget->m_typeCombo->currentItem();
00119 }
00120 
00121 
00122 void CreateSubprojectDlg::reject()
00123 {
00124         m_bAccepted = false;
00125 }
00126 //END class CreateSubprojectDlg
00127 
00128 
00129 
00130 //BEGIN class LinkerOptionsDlg
00131 LinkerOptionsDlg::LinkerOptionsDlg( LinkerOptions * linkingOptions, QWidget *parent )
00132         : KDialogBase( parent, "Linker Options Dialog", true, "Linker Options", KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true )
00133 {
00134         m_pLinkerOptions = linkingOptions;
00135         m_pWidget = new LinkerOptionsWidget(this);
00136         
00137         ProjectInfo * pi = ProjectManager::self()->currentProject();
00138         assert(pi);
00139         
00140         
00141         //BEGIN Update gplink options
00142         m_pWidget->m_pHexFormat->setCurrentItem( m_pLinkerOptions->hexFormat() );
00143         m_pWidget->m_pOutputMap->setChecked( m_pLinkerOptions->outputMapFile() );
00144         m_pWidget->m_pLibraryDir->setText( m_pLinkerOptions->libraryDir() );
00145         m_pWidget->m_pLinkerScript->setText( m_pLinkerOptions->linkerScript() );
00146         m_pWidget->m_pOther->setText( m_pLinkerOptions->linkerOther() );
00147         //END Update gplink options
00148         
00149         
00150         
00151         //BEGIN Update library widgets
00152         const KURL::List availableInternal = pi->childOutputURLs( ProjectItem::LibraryType );
00153         const QStringList linkedInternal = m_pLinkerOptions->linkedInternal();
00154         
00155         KURL::List::const_iterator end = availableInternal.end();
00156         for ( KURL::List::const_iterator it = availableInternal.begin(); it != end; ++it )
00157         {
00158                 QString relativeURL = KURL::relativeURL( pi->url(), *it );
00159                 QCheckListItem * item = new QCheckListItem( m_pWidget->m_pInternalLibraries, relativeURL, QCheckListItem::CheckBox );
00160                 item->setOn( linkedInternal.contains(relativeURL) );
00161         }
00162         
00163         m_pExternalLibraryRequester = new KURLRequester( 0 );
00164         m_pExternalLibraryRequester->fileDialog()->setURL( "/usr/share/sdcc/lib" );
00165         
00166         delete m_pWidget->m_pExternalLibraries;
00167         m_pWidget->m_pExternalLibraries = new KEditListBox( i18n("Link libraries outside project"), m_pExternalLibraryRequester->customEditor(), m_pWidget );
00168         m_pWidget->m_pExternalLibraries->layout()->setMargin(11);
00169         (dynamic_cast<QGridLayout*>(m_pWidget->layout()))->addMultiCellWidget( m_pWidget->m_pExternalLibraries, 7, 7, 0, 1 );
00170         
00171 #if defined(KDE_MAKE_VERSION)
00172 # if KDE_VERSION >= KDE_MAKE_VERSION(3,4,0)
00173         m_pWidget->m_pExternalLibraries->setButtons( KEditListBox::Add | KEditListBox::Remove );
00174 # endif
00175 #endif
00176         m_pWidget->m_pExternalLibraries->insertStringList( m_pLinkerOptions->linkedExternal() );
00177         //END Update library widgets
00178 
00179         setMainWidget( m_pWidget );
00180         setInitialSize( m_pWidget->rect().size() );
00181 }
00182 
00183 
00184 LinkerOptionsDlg::~LinkerOptionsDlg()
00185 {
00186         delete m_pExternalLibraryRequester;
00187 }
00188 
00189 
00190 void LinkerOptionsDlg::accept()
00191 {
00192         hide();
00193         
00194         QStringList linkedInternal;
00195         for ( QListViewItemIterator internalIt( m_pWidget->m_pInternalLibraries ); internalIt.current(); ++internalIt )
00196         {
00197                 QCheckListItem * item = static_cast<QCheckListItem*>(internalIt.current());
00198                 if ( item->isOn() )
00199                         linkedInternal << item->text();
00200         }
00201         m_pLinkerOptions->setLinkedInternal( linkedInternal );
00202         
00203         m_pLinkerOptions->setLinkedExternal( m_pWidget->m_pExternalLibraries->items() );
00204         m_pLinkerOptions->setHexFormat( (LinkerOptions::HexFormat::type) m_pWidget->m_pHexFormat->currentItem() );
00205         m_pLinkerOptions->setOutputMapFile( m_pWidget->m_pOutputMap->isChecked() );
00206         m_pLinkerOptions->setLibraryDir( m_pWidget->m_pLibraryDir->text() );
00207         m_pLinkerOptions->setLinkerScript( m_pWidget->m_pLinkerScript->text() );
00208         m_pLinkerOptions->setLinkerOther( m_pWidget->m_pOther->text() );
00209 }
00210 
00211 
00212 void LinkerOptionsDlg::reject()
00213 {
00214 }
00215 //END class LinkerOptionsDlg
00216 
00217 
00218 
00219 //BEGIN class ProcessingOptionsDlg
00220 ProcessingOptionsDlg::ProcessingOptionsDlg( ProjectItem * projectItem, QWidget *parent )
00221         : KDialogBase( parent, "Processing Options Dialog", true, "Processing Options", KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true )
00222 {
00223         m_pProjectItem = projectItem;
00224         m_pWidget = new ProcessingOptionsWidget(this);
00225         
00226         m_pWidget->m_pMicroSelect->setEnabled( !projectItem->useParentMicroID() );
00227         
00228         switch ( projectItem->type() )
00229         {
00230                 case ProjectItem::ProjectType:
00231                         m_pWidget->m_pOutputURL->setEnabled(false);
00232                         break;
00233                         
00234                 case ProjectItem::FileType:
00235                         m_pWidget->m_pOutputURL->setEnabled(true);
00236                         break;
00237                         
00238                 case ProjectItem::ProgramType:
00239                 case ProjectItem::LibraryType:
00240                         m_pWidget->m_pOutputURL->setEnabled(false);
00241                         break;
00242         }
00243         
00244         m_pWidget->m_pOutputURL->setURL( projectItem->outputURL().path() );
00245         m_pWidget->m_pMicroSelect->setMicro( projectItem->microID() );
00246         
00247         setMainWidget( m_pWidget );
00248         setInitialSize( m_pWidget->rect().size() );
00249 }
00250 
00251 
00252 ProcessingOptionsDlg::~ProcessingOptionsDlg()
00253 {
00254 }
00255 
00256 
00257 void ProcessingOptionsDlg::accept()
00258 {
00259         hide();
00260         
00261         if ( m_pWidget->m_pOutputURL->isEnabled() )
00262                 m_pProjectItem->setOutputURL( m_pWidget->m_pOutputURL->url() );
00263         
00264         if ( m_pWidget->m_pMicroSelect->isEnabled() )
00265                 m_pProjectItem->setMicroID( m_pWidget->m_pMicroSelect->micro() );
00266 }
00267 
00268 
00269 void ProcessingOptionsDlg::reject()
00270 {
00271 }
00272 //END class ProcessingOptionsDlg
00273 
00274 

Generated on Tue May 8 17:05:32 2007 for KTechLab by  doxygen 1.5.1