~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/cpp/classgeneratorconfig.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
*   Copyright (C) 2003 by Alexander Dymo                                  *
3
 
*   cloudtemple@mksat.net                                                 *
4
 
*                                                                         *
5
 
*   This program is free software; you can redistribute it and/or modify  *
6
 
*   it under the terms of the GNU General Public License as published by  *
7
 
*   the Free Software Foundation; either version 2 of the License, or     *
8
 
*   (at your option) any later version.                                   *
9
 
*                                                                         *
10
 
***************************************************************************/
11
 
 
12
 
#include <qcheckbox.h>
13
 
#include <qcombobox.h>
14
 
#include <qtextedit.h>
15
 
#include <qfile.h>
16
 
#include <qfileinfo.h>
17
 
 
18
 
#include <kstandarddirs.h>
19
 
#include <kconfig.h>
20
 
 
21
 
#include "cppsupportfactory.h"
22
 
#include "classgeneratorconfig.h"
23
 
 
24
 
ClassGeneratorConfig::ClassGeneratorConfig( QWidget* parent, const char* name, WFlags fl )
25
 
                : ClassGeneratorConfigBase( parent, name, fl )
26
 
{
27
 
        readConfig();
28
 
        currTemplate = &cppHeaderText;
29
 
        template_edit->setText( *currTemplate );
30
 
}
31
 
 
32
 
ClassGeneratorConfig::ClassGeneratorConfig( QString v_cppHeaderText, QString v_cppSourceText,
33
 
        QString v_objcHeaderText, QString v_objcSourceText,
34
 
        QString v_gtkHeaderText, QString v_gtkSourceText,
35
 
        NameCase v_fileCase, NameCase v_defCase, NameCase v_superCase,
36
 
        bool v_showAuthor, bool v_genDoc, bool v_reformat,
37
 
        QWidget* parent, const char* name, WFlags fl )
38
 
                : ClassGeneratorConfigBase( parent, name, fl ),
39
 
                cppHeaderText( v_cppHeaderText ), cppSourceText( v_cppSourceText ),
40
 
                objcHeaderText( v_objcHeaderText ), objcSourceText( v_objcSourceText ),
41
 
                gtkHeaderText( v_gtkHeaderText ), gtkSourceText( v_gtkSourceText )
42
 
{
43
 
        filecase_box->setCurrentItem( ( int ) v_fileCase );
44
 
        defcase_box->setCurrentItem( ( int ) v_defCase );
45
 
        supercase_box->setCurrentItem( ( int ) v_superCase );
46
 
        author_box->setChecked( v_showAuthor );
47
 
        doc_box->setChecked( v_genDoc );
48
 
        reformat_box->setChecked( v_reformat );
49
 
 
50
 
        currTemplate = &cppHeaderText;
51
 
}
52
 
 
53
 
ClassGeneratorConfig::~ClassGeneratorConfig()
54
 
{}
55
 
 
56
 
/*$SPECIALIZATION$*/
57
 
void ClassGeneratorConfig::templateTypeChanged( int type )
58
 
{
59
 
        *currTemplate = template_edit->text();
60
 
 
61
 
        currTemplate = identifyTemplate( type );
62
 
        template_edit->setText( *currTemplate );
63
 
}
64
 
 
65
 
QString ClassGeneratorConfig::cppHeader()
66
 
{
67
 
        if ( currTemplate == &cppHeaderText )
68
 
                * currTemplate = template_edit->text();
69
 
        return cppHeaderText;
70
 
}
71
 
 
72
 
QString ClassGeneratorConfig::cppSource()
73
 
{
74
 
        if ( currTemplate == &cppSourceText )
75
 
                * currTemplate = template_edit->text();
76
 
        return cppSourceText;
77
 
}
78
 
 
79
 
QString ClassGeneratorConfig::objcHeader()
80
 
{
81
 
        if ( currTemplate == &objcHeaderText )
82
 
                * currTemplate = template_edit->text();
83
 
        return objcHeaderText;
84
 
}
85
 
 
86
 
QString ClassGeneratorConfig::objcSource()
87
 
{
88
 
        if ( currTemplate == &objcSourceText )
89
 
                * currTemplate = template_edit->text();
90
 
        return objcSourceText;
91
 
}
92
 
 
93
 
QString ClassGeneratorConfig::gtkHeader()
94
 
{
95
 
        if ( currTemplate == &gtkHeaderText )
96
 
                * currTemplate = template_edit->text();
97
 
        return gtkHeaderText;
98
 
}
99
 
 
100
 
QString ClassGeneratorConfig::gtkSource()
101
 
{
102
 
        if ( currTemplate == &gtkSourceText )
103
 
                * currTemplate = template_edit->text();
104
 
        return gtkSourceText;
105
 
}
106
 
 
107
 
ClassGeneratorConfig::NameCase ClassGeneratorConfig::fileCase()
108
 
{
109
 
        return ( NameCase ) filecase_box->currentItem();
110
 
}
111
 
 
112
 
ClassGeneratorConfig::NameCase ClassGeneratorConfig::defCase()
113
 
{
114
 
        return ( NameCase ) defcase_box->currentItem();
115
 
}
116
 
 
117
 
ClassGeneratorConfig::NameCase ClassGeneratorConfig::superCase()
118
 
{
119
 
        return ( NameCase ) supercase_box->currentItem();
120
 
}
121
 
 
122
 
bool ClassGeneratorConfig::showAuthor()
123
 
{
124
 
        return author_box->isChecked();
125
 
}
126
 
 
127
 
bool ClassGeneratorConfig::genDoc()
128
 
{
129
 
        return doc_box->isChecked();
130
 
}
131
 
 
132
 
QString *ClassGeneratorConfig::identifyTemplate( int value )
133
 
{
134
 
        switch ( value )
135
 
        {
136
 
        case 0:
137
 
                return & cppHeaderText;
138
 
        case 1:
139
 
                return &cppSourceText;
140
 
        case 2:
141
 
                return &objcHeaderText;
142
 
        case 3:
143
 
                return &objcSourceText;
144
 
        case 4:
145
 
                return &gtkHeaderText;
146
 
        case 5:
147
 
                return &gtkSourceText;
148
 
        }
149
 
        return 0;
150
 
}
151
 
 
152
 
void ClassGeneratorConfig::readConfig()
153
 
{
154
 
        KConfig * config = CppSupportFactory::instance() ->config();
155
 
        if ( config )
156
 
        {
157
 
                config->setGroup( "Class Generator" );
158
 
 
159
 
                filecase_box->setCurrentItem( config->readNumEntry( "File Name Case", 0 ) );
160
 
                defcase_box->setCurrentItem( config->readNumEntry( "Defines Case", 1 ) );
161
 
                supercase_box->setCurrentItem( config->readNumEntry( "Superclasss Name Case", 0 ) );
162
 
 
163
 
                author_box->setChecked( config->readBoolEntry( "Show Author Name", 1 ) );
164
 
                doc_box->setChecked( config->readBoolEntry( "Generate Empty Documentation", 1 ) );
165
 
 
166
 
                reformat_box->setChecked( config->readBoolEntry( "Reformat Source", 0 ) );
167
 
 
168
 
                KStandardDirs *dirs = CppSupportFactory::instance() ->dirs();
169
 
 
170
 
                cppHeaderText = templateText( dirs->findResource( "newclasstemplates", "cpp_header" ) );
171
 
                cppSourceText = templateText( dirs->findResource( "newclasstemplates", "cpp_source" ) );
172
 
                objcHeaderText = templateText( dirs->findResource( "newclasstemplates", "objc_header" ) );
173
 
                objcSourceText = templateText( dirs->findResource( "newclasstemplates", "objc_source" ) );
174
 
                gtkHeaderText = templateText( dirs->findResource( "newclasstemplates", "gtk_header" ) );
175
 
                gtkSourceText = templateText( dirs->findResource( "newclasstemplates", "gtk_source" ) );
176
 
        }
177
 
}
178
 
 
179
 
 
180
 
QString ClassGeneratorConfig::templateText( QString path )
181
 
{
182
 
        QFileInfo f( path );
183
 
        if ( f.exists() )
184
 
        {
185
 
                QFile file( path );
186
 
                if ( file.open( IO_ReadOnly ) )
187
 
                {
188
 
                        QTextStream stream( &file );
189
 
                        return stream.read();
190
 
                }
191
 
                else
192
 
                        return "";
193
 
        }
194
 
        else
195
 
                return "";
196
 
}
197
 
 
198
 
void ClassGeneratorConfig::storeConfig()
199
 
{
200
 
        KConfig * config = CppSupportFactory::instance() ->config();
201
 
        if ( config )
202
 
        {
203
 
                config->setGroup( "Class Generator" );
204
 
 
205
 
                config->writeEntry( "File Name Case", filecase_box->currentItem() );
206
 
                config->writeEntry( "Defines Case", defcase_box->currentItem() );
207
 
                config->writeEntry( "Superclasss Name Case", supercase_box->currentItem() );
208
 
 
209
 
                config->writeEntry( "Show Author Name", author_box->isChecked() );
210
 
                config->writeEntry( "Generate Empty Documentation", doc_box->isChecked() );
211
 
 
212
 
                config->writeEntry( "Reformat Source", reformat_box->isChecked() );
213
 
 
214
 
                KStandardDirs *dirs = CppSupportFactory::instance() ->dirs();
215
 
 
216
 
                saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "cpp_header", cppHeader() );
217
 
                saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "cpp_source", cppSource() );
218
 
                saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "objc_header", objcHeader() );
219
 
                saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "objc_source", objcSource() );
220
 
                saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "gtk_header", gtkHeader() );
221
 
                saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "gtk_source", gtkSource() );
222
 
        }
223
 
}
224
 
 
225
 
void ClassGeneratorConfig::saveTemplateText( QString path, QString content )
226
 
{
227
 
        QFile f( path );
228
 
        if ( f.open( IO_WriteOnly ) )
229
 
        {
230
 
                QTextStream stream( &f );
231
 
                stream << content;
232
 
                f.close();
233
 
        }
234
 
}
235
 
 
236
 
#include "classgeneratorconfig.moc"