KDevelop API Documentation

classgeneratorconfig.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002 *   Copyright (C) 2003 by Alexander Dymo                                  *
00003 *   cloudtemple@mksat.net                                                 *
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 <qcheckbox.h>
00013 #include <qcombobox.h>
00014 #include <qtextedit.h>
00015 #include <qfile.h>
00016 #include <qfileinfo.h>
00017 
00018 #include <kstandarddirs.h>
00019 #include <kconfig.h>
00020 
00021 #include "cppsupportfactory.h"
00022 #include "classgeneratorconfig.h"
00023 
00024 ClassGeneratorConfig::ClassGeneratorConfig(QWidget* parent, const char* name, WFlags fl)
00025 : ClassGeneratorConfigBase(parent,name,fl)
00026 {
00027     readConfig();
00028     currTemplate = &cppHeaderText;
00029     template_edit->setText(*currTemplate);
00030 }
00031 
00032 ClassGeneratorConfig::ClassGeneratorConfig(QString v_cppHeaderText, QString v_cppSourceText, 
00033     QString v_objcHeaderText, QString v_objcSourceText,
00034     QString v_gtkHeaderText, QString v_gtkSourceText,
00035     NameCase v_fileCase, NameCase v_defCase, NameCase v_superCase,
00036     bool v_showAuthor, bool v_genDoc, bool v_reformat,
00037     QWidget* parent, const char* name, WFlags fl )
00038     : ClassGeneratorConfigBase(parent,name,fl),
00039     cppHeaderText(v_cppHeaderText), cppSourceText(v_cppSourceText),
00040     objcHeaderText(v_objcHeaderText), objcSourceText(v_objcSourceText),
00041     gtkHeaderText(v_gtkHeaderText), gtkSourceText(v_gtkSourceText)
00042 {
00043     filecase_box->setCurrentItem((int)v_fileCase);
00044     defcase_box->setCurrentItem((int)v_defCase);
00045     supercase_box->setCurrentItem((int)v_superCase);
00046     author_box->setChecked(v_showAuthor);
00047     doc_box->setChecked(v_genDoc);
00048     reformat_box->setChecked(v_reformat);
00049 
00050     currTemplate = &cppHeaderText;
00051 }
00052 
00053 ClassGeneratorConfig::~ClassGeneratorConfig()
00054 {
00055 }
00056 
00057 /*$SPECIALIZATION$*/
00058 void ClassGeneratorConfig::templateTypeChanged(int type)
00059 {
00060     *currTemplate = template_edit->text();
00061 
00062     currTemplate = identifyTemplate(type);
00063     template_edit->setText(*currTemplate);
00064 }
00065 
00066 QString ClassGeneratorConfig::cppHeader()
00067 {
00068     if (currTemplate == &cppHeaderText)
00069         *currTemplate = template_edit->text();
00070     return cppHeaderText;
00071 }
00072 
00073 QString ClassGeneratorConfig::cppSource()
00074 {
00075     if (currTemplate == &cppSourceText)
00076         *currTemplate = template_edit->text();
00077     return cppSourceText;
00078 }
00079 
00080 QString ClassGeneratorConfig::objcHeader()
00081 {
00082     if (currTemplate == &objcHeaderText)
00083         *currTemplate = template_edit->text();
00084     return objcHeaderText;
00085 }
00086 
00087 QString ClassGeneratorConfig::objcSource()
00088 {
00089     if (currTemplate == &objcSourceText)
00090         *currTemplate = template_edit->text();
00091     return objcSourceText;
00092 }
00093 
00094 QString ClassGeneratorConfig::gtkHeader()
00095 {
00096     if (currTemplate == &gtkHeaderText)
00097         *currTemplate = template_edit->text();
00098     return gtkHeaderText;
00099 }
00100 
00101 QString ClassGeneratorConfig::gtkSource()
00102 {
00103     if (currTemplate == &gtkSourceText)
00104         *currTemplate = template_edit->text();
00105     return gtkSourceText;
00106 }
00107 
00108 ClassGeneratorConfig::NameCase ClassGeneratorConfig::fileCase()
00109 {
00110     return (NameCase)filecase_box->currentItem();
00111 }
00112 
00113 ClassGeneratorConfig::NameCase ClassGeneratorConfig::defCase()
00114 {
00115     return (NameCase)defcase_box->currentItem();
00116 }
00117 
00118 ClassGeneratorConfig::NameCase ClassGeneratorConfig::superCase()
00119 {
00120     return (NameCase)supercase_box->currentItem();
00121 }
00122 
00123 bool ClassGeneratorConfig::showAuthor()
00124 {
00125     return author_box->isChecked();
00126 }
00127 
00128 bool ClassGeneratorConfig::genDoc()
00129 {
00130     return doc_box->isChecked();
00131 }
00132 
00133 QString *ClassGeneratorConfig::identifyTemplate(int value)
00134 {
00135     switch( value ){
00136         case 0: return &cppHeaderText;
00137         case 1: return &cppSourceText;
00138         case 2: return &objcHeaderText;
00139         case 3: return &objcSourceText;
00140         case 4: return &gtkHeaderText;
00141         case 5: return &gtkSourceText;
00142     }
00143     return 0;
00144 }
00145 
00146 void ClassGeneratorConfig::readConfig()
00147 {
00148     KConfig *config = CppSupportFactory::instance()->config();
00149     if (config)
00150     {
00151         config->setGroup("Class Generator");
00152         
00153         filecase_box->setCurrentItem(config->readNumEntry("File Name Case", 0));
00154         defcase_box->setCurrentItem(config->readNumEntry("Defines Case", 1));
00155         supercase_box->setCurrentItem(config->readNumEntry("Superclasss Name Case", 0));
00156         
00157         author_box->setChecked(config->readBoolEntry("Show Author Name", 1));
00158         doc_box->setChecked(config->readBoolEntry("Generate Empty Documentation", 1));
00159 
00160         reformat_box->setChecked(config->readBoolEntry("Reformat Source", 0));
00161 
00162         KStandardDirs *dirs = CppSupportFactory::instance()->dirs();
00163 
00164         cppHeaderText = templateText( dirs->findResource("newclasstemplates", "cpp_header") );
00165         cppSourceText = templateText( dirs->findResource("newclasstemplates", "cpp_source") );
00166         objcHeaderText = templateText( dirs->findResource("newclasstemplates", "objc_header") );
00167         objcSourceText = templateText( dirs->findResource("newclasstemplates", "objc_source") );
00168         gtkHeaderText = templateText( dirs->findResource("newclasstemplates", "gtk_header") );
00169         gtkSourceText = templateText( dirs->findResource("newclasstemplates", "gtk_source") );
00170     }
00171 }
00172     
00173     
00174 QString ClassGeneratorConfig::templateText(QString path)
00175 {
00176     QFileInfo f(path);
00177     if (f.exists())
00178     {
00179         QFile file(path);
00180         if (file.open(IO_ReadOnly))
00181         {
00182             QTextStream stream( &file );
00183             return stream.read();
00184         }
00185         else
00186             return "";
00187     }
00188     else
00189         return "";
00190 }
00191 
00192 void ClassGeneratorConfig::storeConfig()
00193 {
00194     KConfig *config = CppSupportFactory::instance()->config();
00195     if (config)
00196     {
00197         config->setGroup("Class Generator");
00198         
00199         config->writeEntry("File Name Case", filecase_box->currentItem());
00200         config->writeEntry("Defines Case", defcase_box->currentItem());
00201         config->writeEntry("Superclasss Name Case", supercase_box->currentItem());
00202 
00203         config->writeEntry("Show Author Name", author_box->isChecked());
00204         config->writeEntry("Generate Empty Documentation", doc_box->isChecked());
00205 
00206         config->writeEntry("Reformat Source", reformat_box->isChecked());
00207 
00208         KStandardDirs *dirs = CppSupportFactory::instance()->dirs();
00209 
00210         saveTemplateText( dirs->saveLocation("newclasstemplates")+"cpp_header", cppHeader() );
00211         saveTemplateText( dirs->saveLocation("newclasstemplates")+"cpp_source", cppSource() );
00212         saveTemplateText( dirs->saveLocation("newclasstemplates")+"objc_header", objcHeader() );
00213         saveTemplateText( dirs->saveLocation("newclasstemplates")+"objc_source", objcSource() );
00214         saveTemplateText( dirs->saveLocation("newclasstemplates")+"gtk_header", gtkHeader() );
00215         saveTemplateText( dirs->saveLocation("newclasstemplates")+"gtk_source", gtkSource() );
00216     }
00217 }
00218 
00219 void ClassGeneratorConfig::saveTemplateText(QString path, QString content)
00220 {
00221     QFile f(path);
00222     if (f.open(IO_WriteOnly) )
00223     {
00224         QTextStream stream( &f );
00225         stream << content;
00226         f.close();
00227     }
00228 }
00229 
00230 #include "classgeneratorconfig.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:45 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003