KDevelop API Documentation

buildtools/autotools/addsubprojectdlg.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 "addsubprojectdlg.h" 00013 00014 #include <qlabel.h> 00015 #include <qlayout.h> 00016 #include <qpushbutton.h> 00017 #include <qstringlist.h> 00018 #include <qtextstream.h> 00019 #include <kbuttonbox.h> 00020 #include <kdebug.h> 00021 #include <kfiledialog.h> 00022 #include <kiconloader.h> 00023 #include <klineedit.h> 00024 #include <kmessagebox.h> 00025 00026 #include "autolistviewitems.h" 00027 00028 #include "kdevmakefrontend.h" 00029 #include "misc.h" 00030 #include "autoprojectpart.h" 00031 #include "autosubprojectview.h" 00032 00033 00034 AddSubprojectDialog::AddSubprojectDialog(AutoProjectPart *part, AutoSubprojectView *view, 00035 SubprojectItem *item, QWidget *parent, const char *name) 00036 : AddSubprojectDlgBase(parent, name, true) 00037 { 00038 setIcon(SmallIcon("folder_new.png")); 00039 00040 connect( createButton, SIGNAL(clicked()), this, SLOT(accept()) ); 00041 connect( cancelButton, SIGNAL(clicked()), this, SLOT(reject()) ); 00042 00043 m_subProject = item; 00044 m_subprojectView = view; 00045 m_part = part; 00046 } 00047 00048 00049 AddSubprojectDialog::~AddSubprojectDialog() 00050 {} 00051 00052 00053 void AddSubprojectDialog::accept() 00054 { 00055 QString name = spEdit->text().stripWhiteSpace(); 00056 00057 if (name.isEmpty()) { 00058 KMessageBox::sorry(this, i18n("You have to give the subproject a name.")); 00059 return; 00060 } 00061 00062 QListViewItem *childItem = m_subProject->firstChild(); 00063 while (childItem) { 00064 if (name == static_cast<SubprojectItem*>(childItem)->subdir) { 00065 KMessageBox::sorry(this, i18n("A subproject with this name already exists.")); 00066 return; 00067 } 00068 childItem = childItem->nextSibling(); 00069 } 00070 00071 00072 #if 0 00073 // check for config.status 00074 if( !QFileInfo(m_part->projectDirectory(), "config.status").exists() ){ 00075 KMessageBox::sorry(this, i18n("There is no config.status in the project root directory. Run 'Configure' first")); 00076 QDialog::accept(); 00077 return; 00078 } 00079 #endif 00080 00081 QDir dir( m_subProject->path ); 00082 QFileInfo file( dir, name ); 00083 00084 if( file.exists() && !file.isDir() ) { 00085 KMessageBox::sorry(this, i18n("A file named %1 already exists.").arg(name)); 00086 QDialog::accept(); 00087 return; 00088 } else if( file.isDir() ) { 00089 if( KMessageBox::warningContinueCancel(this, 00090 i18n("A subdirectory %1 already exists. " 00091 "Do you wish to add it as a subproject?").arg(name)) 00092 == KMessageBox::Cancel ){ 00093 QDialog::accept(); 00094 return; 00095 } 00096 } else if (!dir.mkdir(name)) { 00097 KMessageBox::sorry(this, i18n("Could not create subdirectory %1.").arg(name)); 00098 QDialog::accept(); 00099 return; 00100 } 00101 00102 if(!dir.cd(name)) { 00103 KMessageBox::sorry(this, i18n("Could not access the subdirectory %1.").arg(name)); 00104 QDialog::accept(); 00105 return; 00106 } 00107 00108 // Adjust SUBDIRS variable in containing Makefile.am 00109 if (m_subProject->variables["SUBDIRS"].find("$(TOPSUBDIRS)") != -1) 00110 { 00111 QFile subdirsfile( m_subProject->path + "/subdirs" ); 00112 if ( subdirsfile.open( IO_WriteOnly | IO_Append ) ) 00113 { 00114 QTextStream subdirsstream( &subdirsfile ); 00115 subdirsstream << name << endl; 00116 subdirsfile.close(); 00117 } 00118 } 00119 else if (m_subProject->variables["SUBDIRS"].find("$(AUTODIRS)") != -1) 00120 { 00121 } 00122 else 00123 { 00124 m_subProject->variables["SUBDIRS"] += (" " + name); 00125 QMap<QString,QString> replaceMap; 00126 replaceMap.insert("SUBDIRS", m_subProject->variables["SUBDIRS"]); 00127 AutoProjectTool::modifyMakefileam(m_subProject->path + "/Makefile.am", replaceMap); 00128 } 00129 00130 // Create new item in tree view 00131 SubprojectItem *newitem = new SubprojectItem(m_subProject, name); 00132 newitem->subdir = name; 00133 newitem->path = m_subProject->path + "/" + name; 00134 newitem->variables["INCLUDES"] = m_subProject->variables["INCLUDES"]; 00135 newitem->setOpen(true); 00136 00137 // Move to the bottom of the list 00138 QListViewItem *lastItem = m_subProject->firstChild(); 00139 while (lastItem->nextSibling()) 00140 lastItem = lastItem->nextSibling(); 00141 if (lastItem != newitem) 00142 newitem->moveItem(lastItem); 00143 00144 // Create a Makefile in the new subdirectory 00145 00146 QFile f( dir.filePath("Makefile.am") ); 00147 if (f.exists()) { 00148 m_subprojectView->parse( newitem ); 00149 } else { 00150 if (!f.open(IO_WriteOnly)) { 00151 KMessageBox::sorry(this, i18n("Could not create Makefile.am in subdirectory %1").arg(name)); 00152 return; 00153 } 00154 QTextStream stream(&f); 00155 stream << "INCLUDES = " << newitem->variables["INCLUDES"] << endl << "METASOURCES = AUTO" << endl; 00156 f.close(); 00157 } 00158 00159 00160 00161 // if !isKDE: add the new sub-proj to configure.in 00162 if ( !m_part->isKDE() ) { 00163 QString projroot = m_part->projectDirectory() + "/"; 00164 QString subdirectory = dir.path(); 00165 QString relpath = subdirectory.replace(0, projroot.length(),""); 00166 00167 QString configurein = projroot + "configure.in"; 00168 00169 QStringList list = AutoProjectTool::configureinLoadMakefiles(configurein); 00170 list.push_back( relpath + "/Makefile" ); 00171 AutoProjectTool::configureinSaveMakefiles(configurein, list); 00172 } 00173 00174 #if 0 00175 QString relmakefile = (m_subProject->path + "/" + name + "/Makefile").mid(m_part->projectDirectory().length()+1); 00176 kdDebug(9020) << "Relative makefile path: " << relmakefile << endl; 00177 00178 QString cmdline = "cd "; 00179 cmdline += m_part->projectDirectory(); 00180 cmdline += " && automake "; 00181 cmdline += relmakefile; 00182 cmdline += " && CONFIG_HEADERS=config.h CONFIG_FILES="; 00183 cmdline += relmakefile; 00184 cmdline += " ./config.status"; 00185 00186 m_part->makeFrontend()->queueCommand( m_part->projectDirectory(), cmdline ); 00187 m_part->makeFrontend()->queueCommand( m_part->projectDirectory(), m_part->configureCommand() ); 00188 #endif 00189 00190 m_part->needMakefileCvs(); 00191 00192 QDialog::accept(); 00193 } 00194 00195 #include "addsubprojectdlg.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Oct 19 08:01:36 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003