KDevelop API Documentation

targetoptionsdlg.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2001 by Bernd Gehrmann                                  *
00003  *   bernd@kdevelop.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 
00012 #include "targetoptionsdlg.h"
00013 
00014 #include <qcheckbox.h>
00015 #include <qheader.h>
00016 #include <qlabel.h>
00017 #include <qlayout.h>
00018 #include <qlineedit.h>
00019 #include <qregexp.h>
00020 #include <kbuttonbox.h>
00021 #include <kdialog.h>
00022 #include <kinputdialog.h>
00023 #include <klocale.h>
00024 #include <knotifyclient.h>
00025 
00026 #include "autolistviewitems.h"
00027 
00028 #include "misc.h"
00029 #include "autoprojectpart.h"
00030 #include "autoprojectwidget.h"
00031 
00032 
00033 TargetOptionsDialog::TargetOptionsDialog(AutoProjectWidget *widget, TargetItem *item,
00034                                          QWidget *parent, const char *name)
00035     : TargetOptionsDialogBase(parent, name, true)
00036 {
00037     setCaption( i18n("Target Options for '%1'").arg(item->name) );
00038     setIcon( SmallIcon("configure") );
00039 
00040     target = item;
00041     m_widget = widget;
00042 
00043     if (item->primary == "PROGRAMS") {
00044         insidelib_label->setText(i18n("Link convenience libraries inside project (LDADD)"));
00045         outsidelib_label->setText(i18n("Link libraries outside project (LDADD)"));
00046     }
00047     else
00048         run_arguments_edit->setEnabled(false);
00049 
00050     insidelib_listview->header()->hide();
00051     outsidelib_listview->header()->hide();
00052     insidelib_listview->setSorting(-1);
00053     outsidelib_listview->setSorting(-1);
00054 
00055     // Insert all convenience libraries as possible linked libraries
00056     QStringList l = widget->allLibraries();
00057     QStringList::ConstIterator it;
00058     QString fulltargetname = m_widget->subprojectDirectory() + "/" + item->name;
00059     for (it = l.begin(); it != l.end(); ++it)
00060         // Do not list the target itself (a target can not link with itself)
00061         if ( !fulltargetname.endsWith(*it) )
00062             (void) new QCheckListItem(insidelib_listview, *it, QCheckListItem::CheckBox);
00063     readConfig();
00064 }
00065 
00066 
00067 TargetOptionsDialog::~TargetOptionsDialog()
00068 {}
00069 
00070 
00071 void TargetOptionsDialog::readConfig()
00072 {
00073     QString flagsstr = target->ldflags;
00074     flagsstr.replace(QRegExp("$(KDE_PLUGIN)"), "-avoid-version -module -no-undefined $(KDE_RPATH)");
00075     QStringList l1 = QStringList::split(QRegExp("[ \t]"), flagsstr);
00076     QStringList::Iterator l1it;
00077 
00078     l1it = l1.find("-all-static");
00079     if (l1it != l1.end()) {
00080         allstatic_box->setChecked(true);
00081         l1.remove(l1it);
00082     }
00083     l1it = l1.find("-avoid-version");
00084     if (l1it != l1.end()) {
00085         avoidversion_box->setChecked(true);
00086         l1.remove(l1it);
00087     }
00088     l1it = l1.find("-module");
00089     if (l1it != l1.end()) {
00090         module_box->setChecked(true);
00091         l1.remove(l1it);
00092     }
00093     l1it = l1.find("-no-undefined");
00094     if (l1it != l1.end()) {
00095         noundefined_box->setChecked(true);
00096         l1.remove(l1it);
00097     }
00098     ldflagsother_edit->setText(l1.join(" "));
00099     dependencies_edit->setText(target->dependencies);
00100 
00101     QString addstr = (target->primary == "PROGRAMS")? target->ldadd : target->libadd;
00102     QStringList l2 = QStringList::split(QRegExp("[ \t]"), addstr);
00103 
00104     bool inlistItem;
00105     QListViewItem *lastItem = 0;
00106     QStringList::Iterator l2it;
00107     QCheckListItem *flitem = static_cast<QCheckListItem*>(insidelib_listview->firstChild());
00108     for (l2it = l2.begin(); l2it != l2.end(); ++l2it) {
00109         inlistItem = false;
00110         QCheckListItem *clitem = static_cast<QCheckListItem*>(insidelib_listview->firstChild());
00111         if (flitem) {
00112             while (clitem) {
00113                 if (*l2it == ("$(top_builddir)/" + clitem->text())) {
00114                     clitem->setOn(true);
00115                     // move this item to the "top of the list"
00116                     if (flitem != clitem)
00117                       clitem->moveItem(flitem);
00118                     // move the "top of the list" one item down
00119                     flitem = static_cast<QCheckListItem*>(flitem->nextSibling());
00120                     inlistItem = true;
00121                     break;
00122                 }
00123                 clitem = static_cast<QCheckListItem*>(clitem->nextSibling());
00124             }
00125         }
00126         if ( inlistItem == false ) {
00127             QListViewItem *item = new QListViewItem(outsidelib_listview, *l2it);
00128             if (lastItem)
00129                 item->moveItem(lastItem);
00130             lastItem = item;
00131         }
00132     }
00133 
00134     if (target->primary == "PROGRAMS")
00135         run_arguments_edit->setText(DomUtil::readEntry(*m_widget->m_part->projectDom(), "/kdevautoproject/run/runarguments/" + target->name));
00136 }
00137 
00138 
00139 void TargetOptionsDialog::storeConfig()
00140 {
00141     QStringList flagslist;
00142     if (allstatic_box->isChecked())
00143         flagslist.append("-all-static");
00144     if (avoidversion_box->isChecked())
00145         flagslist.append("-avoid-version");
00146     if (module_box->isChecked())
00147         flagslist.append("-module");
00148     if (noundefined_box->isChecked())
00149         flagslist.append("-no-undefined");
00150     flagslist.append(ldflagsother_edit->text());
00151     QString new_ldflags = flagslist.join(" ");
00152 
00153     QStringList liblist;
00154     QCheckListItem *clitem = static_cast<QCheckListItem*>(insidelib_listview->firstChild());
00155     while (clitem) {
00156         if( clitem->isOn() )
00157             liblist.append("$(top_builddir)/" + clitem->text());
00158         clitem = static_cast<QCheckListItem*>(clitem->nextSibling());
00159     }
00160     clitem = static_cast<QCheckListItem*>(outsidelib_listview->firstChild());
00161     while (clitem) {
00162         liblist.append(clitem->text());
00163         clitem = static_cast<QCheckListItem*>(clitem->nextSibling());
00164     }
00165     QString new_addstr = liblist.join(" ");
00166 
00167     QString canonname = AutoProjectTool::canonicalize(target->name);
00168     QMap<QString, QString> replaceMap;
00169 
00170     if (target->primary == "PROGRAMS") {
00171         QString old_ldadd = target->ldadd;
00172         if (new_addstr != old_ldadd) {
00173             target->ldadd = new_addstr;
00174             replaceMap.insert(canonname + "_LDADD", new_addstr);
00175         }
00176     }
00177 
00178     if (target->primary == "LIBRARIES" || target->primary == "LTLIBRARIES") {
00179         QString old_libadd = target->libadd;
00180         if (new_addstr != old_libadd) {
00181             target->libadd = new_addstr;
00182             replaceMap.insert(canonname + "_LIBADD", new_addstr);
00183         }
00184     }
00185 
00186     QString old_ldflags = target->ldflags;
00187     if (new_ldflags != old_ldflags) {
00188         target->ldflags = new_ldflags;
00189         replaceMap.insert(canonname + "_LDFLAGS", new_ldflags);
00190     }
00191 
00192     QString new_dependencies = dependencies_edit->text();
00193     QString old_dependencies = target->dependencies;
00194     if (new_dependencies != old_dependencies) {
00195         target->dependencies = new_dependencies;
00196         if (!new_dependencies.isEmpty())
00197             replaceMap.insert(canonname + "_DEPENDENCIES", new_dependencies);
00198     }
00199 
00200     // We can safely assume that this target is in the active sub project
00201     AutoProjectTool::modifyMakefileam(m_widget->subprojectDirectory() + "/Makefile.am", replaceMap);
00202 
00203     if (target->primary == "PROGRAMS")
00204         DomUtil::writeEntry(*m_widget->m_part->projectDom(), "/kdevautoproject/run/runarguments/" + target->name, run_arguments_edit->text());
00205 }
00206 
00207 
00208 void TargetOptionsDialog::insideMoveUpClicked()
00209 {
00210     if (!insidelib_listview->currentItem())
00211         return;
00212     if (insidelib_listview->currentItem() == insidelib_listview->firstChild()) {
00213         KNotifyClient::beep();
00214         return;
00215     }
00216 
00217     QListViewItem *item = insidelib_listview->firstChild();
00218     while (item->nextSibling() != insidelib_listview->currentItem())
00219         item = item->nextSibling();
00220     item->moveItem(insidelib_listview->currentItem());
00221 }
00222 
00223 
00224 void TargetOptionsDialog::insideMoveDownClicked()
00225 {
00226    if (!insidelib_listview->currentItem())
00227        return;
00228 
00229    if (insidelib_listview->currentItem()->nextSibling() == 0) {
00230         KNotifyClient::beep();
00231         return;
00232    }
00233 
00234    insidelib_listview->currentItem()->moveItem(insidelib_listview->currentItem()->nextSibling());
00235 }
00236 
00237 
00238 void TargetOptionsDialog::outsideMoveUpClicked()
00239 {
00240     if (!outsidelib_listview->currentItem())
00241         return;
00242     if (outsidelib_listview->currentItem() == outsidelib_listview->firstChild()) {
00243         KNotifyClient::beep();
00244         return;
00245     }
00246 
00247     QListViewItem *item = outsidelib_listview->firstChild();
00248     while (item->nextSibling() != outsidelib_listview->currentItem())
00249         item = item->nextSibling();
00250     item->moveItem(outsidelib_listview->currentItem());
00251 }
00252 
00253 
00254 void TargetOptionsDialog::outsideMoveDownClicked()
00255 {
00256    if (!outsidelib_listview->currentItem())
00257        return;
00258    if (outsidelib_listview->currentItem()->nextSibling() == 0) {
00259         KNotifyClient::beep();
00260         return;
00261    }
00262 
00263    outsidelib_listview->currentItem()->moveItem(outsidelib_listview->currentItem()->nextSibling());
00264 }
00265 
00266 
00267 void TargetOptionsDialog::outsideAddClicked()
00268 {
00269     bool ok;
00270     QString dir = KInputDialog::getText(i18n("Add Library"), i18n("Add library:"), "-l", &ok, 0);
00271     if (ok && !dir.isEmpty() && dir != "-l")
00272         new QListViewItem(outsidelib_listview, dir);
00273 }
00274 
00275 
00276 void TargetOptionsDialog::outsideEditClicked()
00277 {
00278     if ( (outsidelib_listview->childCount()==0) || (outsidelib_listview->currentItem() == 0) )
00279         return;
00280     bool ok;
00281     QString dir = KInputDialog::getText(i18n("Edit External Library"), i18n("Edit external library:"),
00282             outsidelib_listview->currentItem()-> text(0), &ok, 0);
00283     if (ok && !dir.isEmpty())
00284         outsidelib_listview->currentItem()-> setText(0, dir);
00285 }
00286 
00287 
00288 void TargetOptionsDialog::outsideRemoveClicked()
00289 {
00290     delete outsidelib_listview->currentItem();
00291 }
00292 
00293 
00294 void TargetOptionsDialog::accept()
00295 {
00296     storeConfig();
00297     QDialog::accept();
00298 }
00299 
00300 #include "targetoptionsdlg.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:40 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003