KDevelop API Documentation

buildtools/autotools/addfiledlg.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2001-2002 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 "addfiledlg.h" 00013 00014 #include <qcheckbox.h> 00015 #include <qfile.h> 00016 #include <qfileinfo.h> 00017 #include <qlabel.h> 00018 #include <qlayout.h> 00019 #include <qlineedit.h> 00020 #include <qpushbutton.h> 00021 #include <qtextstream.h> 00022 00023 #include <kbuttonbox.h> 00024 #include <kdebug.h> 00025 #include <kdialog.h> 00026 #include <klineedit.h> 00027 #include <kmessagebox.h> 00028 #include <ksqueezedtextlabel.h> 00029 #include <kurl.h> 00030 00031 #include "autolistviewitems.h" 00032 00033 #include "filetemplate.h" 00034 #include "misc.h" 00035 #include "urlutil.h" 00036 #include "autoprojectpart.h" 00037 #include "autoprojectwidget.h" 00038 00039 #include "kdevpartcontroller.h" 00040 00041 AddFileDialog::AddFileDialog(AutoProjectPart *part, AutoProjectWidget *widget, 00042 SubprojectItem *spitem, TargetItem *item, 00043 QWidget *parent, const char *name) 00044 : AddFileDlgBase(parent, name, true) 00045 { 00046 connect ( createButton, SIGNAL ( clicked() ), this, SLOT ( accept() ) ); 00047 connect ( cancelButton, SIGNAL ( clicked() ), this, SLOT ( reject() ) ); 00048 00049 directoryLabel->setText ( spitem->path ); 00050 if ( item->name.isEmpty() ) 00051 targetLabel->setText ( i18n ( "%1 in %2" ).arg ( item->primary ).arg ( item->prefix ) ); 00052 else 00053 targetLabel->setText ( item->name ); 00054 00055 setIcon ( SmallIcon ( "filenew.png" ) ); 00056 00057 m_part = part; 00058 m_widget = widget; 00059 subProject = spitem; 00060 target = item; 00061 } 00062 00063 00064 AddFileDialog::~AddFileDialog() 00065 {} 00066 00067 00068 void AddFileDialog::accept() 00069 { 00070 QString name = fileEdit->text(); 00071 if (name.find('/') != -1) { 00072 KMessageBox::sorry(this, i18n("Please enter the file name without '/' and so on.")); 00073 return; 00074 } 00075 00076 QListViewItem *child = target->firstChild(); 00077 while (child) { 00078 FileItem *item = static_cast<FileItem*>(child); 00079 if (name == item->name) { 00080 KMessageBox::sorry(this, i18n("This file is already in the target.")); 00081 return; 00082 } 00083 child = child->nextSibling(); 00084 } 00085 00086 if (templateCheckBox->isChecked()) { 00087 QString srcdir = m_part->projectDirectory(); 00088 QString destdir = subProject->path; 00089 QString destpath = destdir + "/" + name; 00090 if (QFileInfo(destpath).exists()) { 00091 KMessageBox::sorry(this, i18n("<b>A file with this name already exists!</b><br><br>Please use the \"Add existing file\" dialog!")); 00092 return; 00093 } 00094 if( !FileTemplate::copy(m_part, QFileInfo(name).extension(), destpath) ) 00095 kdDebug(9020) << "cannot create file " << destpath << endl; 00096 } else { 00097 // create an empty file 00098 QString srcdir = m_part->projectDirectory(); 00099 QString destdir = subProject->path; 00100 QString destpath = destdir + "/" + name; 00101 00102 if (QFileInfo(destpath).exists()) { 00103 KMessageBox::sorry(this, i18n("<b>A file with this name already exists!</b><br><br>Please use the \"Add existing file\" dialog!")); 00104 return; 00105 } 00106 00107 QFile f( destpath ); 00108 if( f.open(IO_WriteOnly) ) 00109 f.close(); 00110 } 00111 00112 FileItem *fitem = m_widget->createFileItem(name, subProject); 00113 target->sources.append(fitem); 00114 target->insertItem(fitem); 00115 00116 QString canontargetname = AutoProjectTool::canonicalize(target->name); 00117 QString varname; 00118 if( target->primary == "PROGRAMS" || target->primary == "LIBRARIES" || target->primary == "LTLIBRARIES" ) 00119 varname = canontargetname + "_SOURCES"; 00120 else 00121 varname = target->prefix + "_" + target->primary; 00122 subProject->variables[varname] += (" " + name); 00123 00124 QMap<QString,QString> replaceMap; 00125 replaceMap.insert(varname, subProject->variables[varname]); 00126 00127 AutoProjectTool::modifyMakefileam(subProject->path + "/Makefile.am", replaceMap); 00128 00129 m_widget->emitAddedFile( subProject->path.mid ( m_part->project()->projectDirectory().length() + 1 ) + "/" + name ); 00130 m_part->partController()->editDocument ( KURL ( subProject->path + "/" + name ) ); 00131 00132 QDialog::accept(); 00133 } 00134 00135 #include "addfiledlg.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:35 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003