summaryrefslogtreecommitdiffstats
path: root/languages/cpp/classgeneratorconfig.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch)
treeacaf47eb0fa12142d3896416a69e74cbf5a72242 /languages/cpp/classgeneratorconfig.cpp
downloadtdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz
tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip
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
Diffstat (limited to 'languages/cpp/classgeneratorconfig.cpp')
-rw-r--r--languages/cpp/classgeneratorconfig.cpp236
1 files changed, 236 insertions, 0 deletions
diff --git a/languages/cpp/classgeneratorconfig.cpp b/languages/cpp/classgeneratorconfig.cpp
new file mode 100644
index 00000000..c6049801
--- /dev/null
+++ b/languages/cpp/classgeneratorconfig.cpp
@@ -0,0 +1,236 @@
+/***************************************************************************
+* Copyright (C) 2003 by Alexander Dymo *
+* cloudtemple@mksat.net *
+* *
+* 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 <qcheckbox.h>
+#include <qcombobox.h>
+#include <qtextedit.h>
+#include <qfile.h>
+#include <qfileinfo.h>
+
+#include <kstandarddirs.h>
+#include <kconfig.h>
+
+#include "cppsupportfactory.h"
+#include "classgeneratorconfig.h"
+
+ClassGeneratorConfig::ClassGeneratorConfig( QWidget* parent, const char* name, WFlags fl )
+ : ClassGeneratorConfigBase( parent, name, fl )
+{
+ readConfig();
+ currTemplate = &cppHeaderText;
+ template_edit->setText( *currTemplate );
+}
+
+ClassGeneratorConfig::ClassGeneratorConfig( QString v_cppHeaderText, QString v_cppSourceText,
+ QString v_objcHeaderText, QString v_objcSourceText,
+ QString v_gtkHeaderText, QString v_gtkSourceText,
+ NameCase v_fileCase, NameCase v_defCase, NameCase v_superCase,
+ bool v_showAuthor, bool v_genDoc, bool v_reformat,
+ QWidget* parent, const char* name, WFlags fl )
+ : ClassGeneratorConfigBase( parent, name, fl ),
+ cppHeaderText( v_cppHeaderText ), cppSourceText( v_cppSourceText ),
+ objcHeaderText( v_objcHeaderText ), objcSourceText( v_objcSourceText ),
+ gtkHeaderText( v_gtkHeaderText ), gtkSourceText( v_gtkSourceText )
+{
+ filecase_box->setCurrentItem( ( int ) v_fileCase );
+ defcase_box->setCurrentItem( ( int ) v_defCase );
+ supercase_box->setCurrentItem( ( int ) v_superCase );
+ author_box->setChecked( v_showAuthor );
+ doc_box->setChecked( v_genDoc );
+ reformat_box->setChecked( v_reformat );
+
+ currTemplate = &cppHeaderText;
+}
+
+ClassGeneratorConfig::~ClassGeneratorConfig()
+{}
+
+/*$SPECIALIZATION$*/
+void ClassGeneratorConfig::templateTypeChanged( int type )
+{
+ *currTemplate = template_edit->text();
+
+ currTemplate = identifyTemplate( type );
+ template_edit->setText( *currTemplate );
+}
+
+QString ClassGeneratorConfig::cppHeader()
+{
+ if ( currTemplate == &cppHeaderText )
+ * currTemplate = template_edit->text();
+ return cppHeaderText;
+}
+
+QString ClassGeneratorConfig::cppSource()
+{
+ if ( currTemplate == &cppSourceText )
+ * currTemplate = template_edit->text();
+ return cppSourceText;
+}
+
+QString ClassGeneratorConfig::objcHeader()
+{
+ if ( currTemplate == &objcHeaderText )
+ * currTemplate = template_edit->text();
+ return objcHeaderText;
+}
+
+QString ClassGeneratorConfig::objcSource()
+{
+ if ( currTemplate == &objcSourceText )
+ * currTemplate = template_edit->text();
+ return objcSourceText;
+}
+
+QString ClassGeneratorConfig::gtkHeader()
+{
+ if ( currTemplate == &gtkHeaderText )
+ * currTemplate = template_edit->text();
+ return gtkHeaderText;
+}
+
+QString ClassGeneratorConfig::gtkSource()
+{
+ if ( currTemplate == &gtkSourceText )
+ * currTemplate = template_edit->text();
+ return gtkSourceText;
+}
+
+ClassGeneratorConfig::NameCase ClassGeneratorConfig::fileCase()
+{
+ return ( NameCase ) filecase_box->currentItem();
+}
+
+ClassGeneratorConfig::NameCase ClassGeneratorConfig::defCase()
+{
+ return ( NameCase ) defcase_box->currentItem();
+}
+
+ClassGeneratorConfig::NameCase ClassGeneratorConfig::superCase()
+{
+ return ( NameCase ) supercase_box->currentItem();
+}
+
+bool ClassGeneratorConfig::showAuthor()
+{
+ return author_box->isChecked();
+}
+
+bool ClassGeneratorConfig::genDoc()
+{
+ return doc_box->isChecked();
+}
+
+QString *ClassGeneratorConfig::identifyTemplate( int value )
+{
+ switch ( value )
+ {
+ case 0:
+ return & cppHeaderText;
+ case 1:
+ return &cppSourceText;
+ case 2:
+ return &objcHeaderText;
+ case 3:
+ return &objcSourceText;
+ case 4:
+ return &gtkHeaderText;
+ case 5:
+ return &gtkSourceText;
+ }
+ return 0;
+}
+
+void ClassGeneratorConfig::readConfig()
+{
+ KConfig * config = CppSupportFactory::instance() ->config();
+ if ( config )
+ {
+ config->setGroup( "Class Generator" );
+
+ filecase_box->setCurrentItem( config->readNumEntry( "File Name Case", 0 ) );
+ defcase_box->setCurrentItem( config->readNumEntry( "Defines Case", 1 ) );
+ supercase_box->setCurrentItem( config->readNumEntry( "Superclasss Name Case", 0 ) );
+
+ author_box->setChecked( config->readBoolEntry( "Show Author Name", 1 ) );
+ doc_box->setChecked( config->readBoolEntry( "Generate Empty Documentation", 1 ) );
+
+ reformat_box->setChecked( config->readBoolEntry( "Reformat Source", 0 ) );
+
+ KStandardDirs *dirs = CppSupportFactory::instance() ->dirs();
+
+ cppHeaderText = templateText( dirs->findResource( "newclasstemplates", "cpp_header" ) );
+ cppSourceText = templateText( dirs->findResource( "newclasstemplates", "cpp_source" ) );
+ objcHeaderText = templateText( dirs->findResource( "newclasstemplates", "objc_header" ) );
+ objcSourceText = templateText( dirs->findResource( "newclasstemplates", "objc_source" ) );
+ gtkHeaderText = templateText( dirs->findResource( "newclasstemplates", "gtk_header" ) );
+ gtkSourceText = templateText( dirs->findResource( "newclasstemplates", "gtk_source" ) );
+ }
+}
+
+
+QString ClassGeneratorConfig::templateText( QString path )
+{
+ QFileInfo f( path );
+ if ( f.exists() )
+ {
+ QFile file( path );
+ if ( file.open( IO_ReadOnly ) )
+ {
+ QTextStream stream( &file );
+ return stream.read();
+ }
+ else
+ return "";
+ }
+ else
+ return "";
+}
+
+void ClassGeneratorConfig::storeConfig()
+{
+ KConfig * config = CppSupportFactory::instance() ->config();
+ if ( config )
+ {
+ config->setGroup( "Class Generator" );
+
+ config->writeEntry( "File Name Case", filecase_box->currentItem() );
+ config->writeEntry( "Defines Case", defcase_box->currentItem() );
+ config->writeEntry( "Superclasss Name Case", supercase_box->currentItem() );
+
+ config->writeEntry( "Show Author Name", author_box->isChecked() );
+ config->writeEntry( "Generate Empty Documentation", doc_box->isChecked() );
+
+ config->writeEntry( "Reformat Source", reformat_box->isChecked() );
+
+ KStandardDirs *dirs = CppSupportFactory::instance() ->dirs();
+
+ saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "cpp_header", cppHeader() );
+ saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "cpp_source", cppSource() );
+ saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "objc_header", objcHeader() );
+ saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "objc_source", objcSource() );
+ saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "gtk_header", gtkHeader() );
+ saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "gtk_source", gtkSource() );
+ }
+}
+
+void ClassGeneratorConfig::saveTemplateText( QString path, QString content )
+{
+ QFile f( path );
+ if ( f.open( IO_WriteOnly ) )
+ {
+ QTextStream stream( &f );
+ stream << content;
+ f.close();
+ }
+}
+
+#include "classgeneratorconfig.moc"