From 114a878c64ce6f8223cfd22d76a20eb16d177e5e Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- buildtools/autotools/addfiledlg.cpp | 135 ++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 buildtools/autotools/addfiledlg.cpp (limited to 'buildtools/autotools/addfiledlg.cpp') diff --git a/buildtools/autotools/addfiledlg.cpp b/buildtools/autotools/addfiledlg.cpp new file mode 100644 index 00000000..46529086 --- /dev/null +++ b/buildtools/autotools/addfiledlg.cpp @@ -0,0 +1,135 @@ +/*************************************************************************** + * Copyright (C) 2001-2002 by Bernd Gehrmann * + * bernd@kdevelop.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "addfiledlg.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "autolistviewitems.h" + +#include "filetemplate.h" +#include "misc.h" +#include "urlutil.h" +#include "autoprojectpart.h" +#include "autoprojectwidget.h" + +#include "kdevpartcontroller.h" + +AddFileDialog::AddFileDialog(AutoProjectPart *part, AutoProjectWidget *widget, + SubprojectItem *spitem, TargetItem *item, + QWidget *parent, const char *name) + : AddFileDlgBase(parent, name, true) +{ + connect ( createButton, SIGNAL ( clicked() ), this, SLOT ( accept() ) ); + connect ( cancelButton, SIGNAL ( clicked() ), this, SLOT ( reject() ) ); + + directoryLabel->setText ( spitem->path ); + if ( item->name.isEmpty() ) + targetLabel->setText ( i18n ( "%1 in %2" ).arg ( item->primary ).arg ( item->prefix ) ); + else + targetLabel->setText ( item->name ); + + setIcon ( SmallIcon ( "filenew.png" ) ); + + m_part = part; + m_widget = widget; + subProject = spitem; + target = item; +} + + +AddFileDialog::~AddFileDialog() +{} + + +void AddFileDialog::accept() +{ + QString name = fileEdit->text(); + if (name.find('/') != -1) { + KMessageBox::sorry(this, i18n("Please enter the file name without '/' and so on.")); + return; + } + + QListViewItem *child = target->firstChild(); + while (child) { + FileItem *item = static_cast(child); + if (name == item->name) { + KMessageBox::sorry(this, i18n("This file is already in the target.")); + return; + } + child = child->nextSibling(); + } + + if (templateCheckBox->isChecked()) { + QString srcdir = m_part->projectDirectory(); + QString destdir = subProject->path; + QString destpath = destdir + "/" + name; + if (QFileInfo(destpath).exists()) { + KMessageBox::sorry(this, i18n("A file with this name already exists.

Please use the \"Add existing file\" dialog.")); + return; + } + if( !FileTemplate::copy(m_part, QFileInfo(name).extension(), destpath) ) + kdDebug(9020) << "cannot create file " << destpath << endl; + } else { + // create an empty file + QString srcdir = m_part->projectDirectory(); + QString destdir = subProject->path; + QString destpath = destdir + "/" + name; + + if (QFileInfo(destpath).exists()) { + KMessageBox::sorry(this, i18n("A file with this name already exists.

Please use the \"Add existing file\" dialog.")); + return; + } + + QFile f( destpath ); + if( f.open(IO_WriteOnly) ) + f.close(); + } + + FileItem *fitem = m_widget->createFileItem(name, subProject); + target->sources.append(fitem); + target->insertItem(fitem); + + QString canontargetname = AutoProjectTool::canonicalize(target->name); + QString varname; + if( target->primary == "PROGRAMS" || target->primary == "LIBRARIES" || target->primary == "LTLIBRARIES" ) + varname = canontargetname + "_SOURCES"; + else + varname = target->prefix + "_" + target->primary; + subProject->variables[varname] += (" " + name); + + QMap replaceMap; + replaceMap.insert(varname, subProject->variables[varname]); + + AutoProjectTool::addToMakefileam(subProject->path + "/Makefile.am", replaceMap); + + m_widget->emitAddedFile( subProject->path.mid ( m_part->project()->projectDirectory().length() + 1 ) + "/" + name ); + m_part->partController()->editDocument ( KURL ( subProject->path + "/" + name ) ); + + QDialog::accept(); +} + +#include "addfiledlg.moc" -- cgit v1.2.1