KDevelop API Documentation

runoptionswidget.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2001-2002 Bernd Gehrmann <bernd@kdevelop.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #include "runoptionswidget.h"
00021 
00022 #include <klocale.h>
00023 #include <kfiledialog.h>
00024 #include <kdirselectdialog.h>
00025 #include <urlutil.h>
00026 
00027 #include <qlineedit.h>
00028 #include <qlistview.h>
00029 #include <qgroupbox.h>
00030 #include <qcheckbox.h>
00031 #include <qradiobutton.h>
00032 #include <qpushbutton.h>
00033 #include <qlabel.h>
00034 
00035 #include "domutil.h"
00036 #include "environmentvariableswidget.h"
00037 
00038 
00039 RunOptionsWidget::RunOptionsWidget(QDomDocument &dom, const QString &configGroup,
00040                                     const QString &buildDirectory, QWidget *parent, const char *name)
00041     : RunOptionsWidgetBase(parent, name),
00042       m_dom(dom), m_configGroup(configGroup)
00043 {
00044     // Create the "Environment Variables" GUI
00045     env_var_group->setColumnLayout( 1, Qt::Vertical );
00046     m_environmentVariablesWidget = new EnvironmentVariablesWidget( dom, configGroup + "/run/envvars", env_var_group );
00047 
00048     // Store the BUILD directory in a KURL
00049     if (buildDirectory.right(1) == "/")
00050         m_buildDirectory = buildDirectory;
00051     else
00052         m_buildDirectory = buildDirectory + "/";
00053     m_buildDirectory.cleanPath();
00054 
00055     // Display the BUILD directory in a label
00056     buildDirectory_label->setText(m_buildDirectory.directory(false, false));
00057 
00058     // Update the "Run Directory" radio buttons
00059     // "Directory where the executable is" is set by default
00060     QString directoryRadioString = DomUtil::readEntry(dom, configGroup + "/run/directoryradio");
00061     if ( directoryRadioString == "build" )
00062         buildDirectory_radio->setChecked(true);
00063     else
00064         if ( directoryRadioString == "custom" )
00065             customDirectory_radio->setChecked(true);
00066         else
00067             executableDirectory_radio->setChecked(true);
00068     directoryRadioChanged();
00069 
00070     // Read the custom directory, store it in a KURL and update it's edit box
00071     QString customRunDirectory = DomUtil::readEntry(dom, configGroup + "/run/customdirectory");
00072     if (customRunDirectory.right(1) == "/")
00073         m_customRunDirectory = customRunDirectory;
00074     else
00075         m_customRunDirectory = customRunDirectory + "/";
00076     m_customRunDirectory.cleanPath();
00077     customRunDirectory_edit->setText(m_customRunDirectory.directory(false, false));
00078 
00079     // Read the main program path, store it in a KURL and update it's edit box
00080     QString mainProgramPath = DomUtil::readEntry(dom, configGroup + "/run/mainprogram");
00081     if ( customDirectory_radio->isChecked() )
00082         m_mainProgramAbsolutePath = mainProgramPath;
00083     else
00084         m_mainProgramAbsolutePath = m_buildDirectory.directory(false, false) + mainProgramPath;
00085     m_mainProgramAbsolutePath.cleanPath();
00086     if ( customDirectory_radio->isChecked() )
00087         mainprogram_edit->setText(m_mainProgramAbsolutePath.path());
00088     else
00089         mainprogram_edit->setText(URLUtil::relativePath(m_buildDirectory.directory(false, false), m_mainProgramAbsolutePath.path(), false));
00090 
00091     // Read the main program command line arguments and store them in the edit box
00092     progargs_edit->setText(DomUtil::readEntry(dom, configGroup + "/run/programargs"));
00093 
00094     startinterminal_box->setChecked(DomUtil::readBoolEntry(dom, configGroup + "/run/terminal"));
00095     autocompile_box->setChecked(DomUtil::readBoolEntry(dom, configGroup + "/run/autocompile", true));
00096 }
00097 
00098 
00099 RunOptionsWidget::~RunOptionsWidget()
00100 {}
00101 
00102 
00103 void RunOptionsWidget::accept()
00104 {
00105     if ( buildDirectory_radio->isChecked() )
00106       DomUtil::writeEntry(m_dom, m_configGroup + "/run/directoryradio", "build");
00107     else
00108       if ( customDirectory_radio->isChecked() )
00109         DomUtil::writeEntry(m_dom, m_configGroup + "/run/directoryradio", "custom");
00110       else
00111         DomUtil::writeEntry(m_dom, m_configGroup + "/run/directoryradio", "executable");
00112     
00113     QString customDir = customRunDirectory_edit->text();
00114     if (customDir.right(1) != "/")
00115         customDir += "/";
00116     DomUtil::writeEntry(m_dom, m_configGroup + "/run/customdirectory", customDir);
00117     DomUtil::writeEntry(m_dom, m_configGroup + "/run/mainprogram", mainprogram_edit->text());
00118     DomUtil::writeEntry(m_dom, m_configGroup + "/run/programargs", progargs_edit->text());
00119     DomUtil::writeBoolEntry(m_dom, m_configGroup + "/run/terminal", startinterminal_box->isChecked());
00120     DomUtil::writeBoolEntry(m_dom, m_configGroup + "/run/autocompile", autocompile_box->isChecked());
00121 
00122     m_environmentVariablesWidget->accept();
00123 }
00124 
00125 
00126 void RunOptionsWidget::directoryRadioChanged()
00127 {
00128     if ( customDirectory_radio->isChecked() ) {
00129         customRunDirectory_edit->setEnabled(true);
00130         browseCustomButton->setEnabled(true);
00131         mainProgram_relativeness_label->setText("( absolute path )");
00132         mainprogram_edit->setText( m_mainProgramAbsolutePath.path() );
00133     } else {
00134         customRunDirectory_edit->setEnabled(false);
00135         browseCustomButton->setEnabled(false);
00136         mainProgram_relativeness_label->setText("( relative to BUILD directory )");
00137         mainprogram_edit->setText( URLUtil::relativePath(m_buildDirectory.directory(false, false), m_mainProgramAbsolutePath.path(), false) );
00138     }  
00139 }
00140 
00141 
00142 void RunOptionsWidget::browseCustomDirectory()
00143 {
00144     QString path = customRunDirectory_edit->text().stripWhiteSpace();
00145     KDirSelectDialog *dlg = new KDirSelectDialog(path, false, this, 0L, true);
00146     dlg->setCaption(i18n("Select Directory"));
00147 
00148     if (dlg->exec()) {
00149     // if after the dialog execution the OK button was selected:
00150         path = dlg->url().path();
00151         if (path.right(1) != "/")
00152             path += "/";   // I find these lines dumb. Why the hell do I always have to add this???
00153                            // In *nix whenever a path has a / in the end it is a directory, period!
00154                            // Why does the url() return without this? Even if I add .directory(false, false)?
00155         if (!path.isEmpty()) {
00156             customRunDirectory_edit->setText(path);
00157         }
00158     }
00159     delete dlg;
00160 }
00161 
00162 
00163 void RunOptionsWidget::browseMainProgram()
00164 {
00165     QString start_directory;
00166     if ( customDirectory_radio->isChecked() )
00167         start_directory = mainprogram_edit->text().stripWhiteSpace();
00168     else
00169         start_directory = m_buildDirectory.directory(false, false);
00170 
00171     KFileDialog *dlg = new KFileDialog(start_directory, QString::null, this, 0, true);
00172     QStringList filters;
00173     filters << "application/x-executable"
00174     << "application/x-shellscript"
00175     << "application/x-perl"
00176     << "application/x-python";
00177     dlg->setMimeFilter(filters);
00178     dlg->setCaption(i18n("Select Main Program Executable"));
00179     QString path = mainprogram_edit->text().stripWhiteSpace();
00180     if (!path.isEmpty()) {
00181         // strip initial "./" if necessary
00182         if ((path.length() > 2) && (path.left(2) == "./"))
00183             path = path.mid(2);
00184 
00185         // the directory where the executable is
00186         QString dir;
00187         int pos = path.findRev("/");
00188         if (path.left(1) != "/")
00189             dir = m_buildDirectory.directory(false, false) + path.left(pos);
00190         else
00191             dir = path.left(pos);
00192 
00193         // Store it all in a KURL
00194         KURL target ( dir );
00195         target.addPath(path.mid(pos + 1));
00196         target.cleanPath();
00197 
00198         // pass it to the dialog
00199         dlg->setURL(KURL::fromPathOrURL( target.directory(false, false) ));
00200         dlg->setSelection(target.filename());
00201     }
00202 
00203     if (dlg->exec()) {
00204     // if after the dialog execution the OK button was selected:
00205         path = dlg->selectedFile().stripWhiteSpace();
00206         if (!path.isEmpty()) {
00207           
00208             m_mainProgramAbsolutePath = path;
00209 
00210             if ( customDirectory_radio->isChecked() ) {
00211             // Store the absolute path
00212 
00213                 mainprogram_edit->setText(path);
00214 
00215             } else {
00216             // Store the path relative to BUILD directory
00217             
00218                 QString relative = URLUtil::relativePath(m_buildDirectory.directory(false, false), path, false);
00219 
00220                 if (relative.isEmpty() == false) {
00221                     mainprogram_edit->setText(relative);
00222                 }
00223             }
00224             
00225         }
00226     }
00227     delete dlg;
00228 }
00229 
00230 #include "runoptionswidget.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 Wed Mar 23 00:03:52 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003