summaryrefslogtreecommitdiffstats
path: root/languages/cpp/createpcsdialog.cpp
blob: 6cebf32d058685f3a7d260f957e20b887a31705a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/***************************************************************************
*   Copyright (C) 2003 by Roberto Raggi                                   *
*   roberto@tdevelop.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 "createpcsdialog.h"
#include "createpcsdialog.moc"
#include "driver.h"
#include "tag_creator.h"
#include "cppsupportpart.h"
#include "setuphelper.h"

#include <catalog.h>
#include <kdevpcsimporter.h>
#include <kdevcoderepository.h>

#include <tdeparts/componentfactory.h>

#include <ktrader.h>
#include <kdebug.h>
#include <klibloader.h>
#include <tdelistbox.h>
#include <kiconloader.h>
#include <tdelistview.h>
#include <tdeapplication.h>
#include <kinstance.h>
#include <kstandarddirs.h>
#include <tdelocale.h>
#include <kstringhandler.h>
#include <klineedit.h>

#include <tqprogressbar.h>
#include <tqheader.h>
#include <tqlabel.h>
#include <tqregexp.h>
#include <tqlayout.h>
#include <tqtimer.h>
#include <tqpushbutton.h>

#include <stdlib.h>
#include <unistd.h>

class CreatePCSDialog::RppDriver: public Driver
{
public:
	RppDriver( Catalog* c )
			: catalog( c )
	{
		setup();
	}

	virtual ~RppDriver()
	{
#if 0 /// \FIXME robe
		TagCreator::destroyDocumentation();
#endif

	}

#if 0 /// \FIXME robe
	void addDocDirectory( const TQString& dir )
	{
		m_docDirectoryList.append( dir );
		TagCreator::setDocumentationDirectories( m_docDirectoryList );
	}
#endif

	void fileParsed( ParsedFile& ast )
	{
		/// @todo increment progress

#if 0 /// @todo show problems
		TQValueList<Problem> l = problems( fileName );
		TQValueList<Problem>::Iterator it = l.begin();
		while ( it != l.end() )
		{
			const Problem & p = *it;
			++it;
		}
#endif

		takeTranslationUnit( ast );

		TagCreator w( ast.fileName(), catalog );
		w.parseTranslationUnit( ast );

		//if( !isResolveDependencesEnabled() )
		//    removeAllMacrosInFile( fileName );
	}

	// setup the preprocessor
	// code provided by Reginald Stadlbauer <reggie@trolltech.com>
	void setup()
	{
        bool ok;   
        TQString gccLibPath = SetupHelper::getGccIncludePath(&ok);
        if (!ok) 
            return;      
		gccLibPath = gccLibPath.replace( TQRegExp( "[\r\n]" ), "" );
		addIncludePath( gccLibPath );
		//addIncludePath( "/usr/include/g++-3" );
		//addIncludePath( "/usr/include/g++" );
        TQStringList lines = SetupHelper::getGccMacros(&ok);
        if (!ok) 
            return;  
        for (TQStringList::ConstIterator it = lines.constBegin(); it != lines.constEnd(); ++it) {
            TQStringList lst = TQStringList::split( ' ', *it );
            if ( lst.count() != 3 )
                continue;
            addMacro( Macro( lst[1], lst[2] ) );
        }
		addMacro( Macro( "__cplusplus", "1" ) );
		addMacro( Macro( "signals", "signals" ) );
		addMacro( Macro( "slots", "slots" ) );
	}

private:
	Catalog* catalog;
#if 0 /// \FIXME

	TQStringList m_docDirectoryList;
#endif
};


class PCSListViewItem: public TDEListViewItem
{
public:
	PCSListViewItem( KService::Ptr ptr, KDevPCSImporter* importer, TQListViewItem* parent )
			: TDEListViewItem( parent ), m_importer( importer )
	{
		init( ptr );
	}
	PCSListViewItem( KService::Ptr ptr, KDevPCSImporter* importer, TQListView* parent )
			: TDEListViewItem( parent ), m_importer( importer )
	{
		init( ptr );
	}

	~PCSListViewItem()
	{
		delete( m_importer );
		m_importer = 0;
	}

	void init( KService::Ptr ptr )
	{
		setText( 0, ptr->comment() );
		setPixmap( 0, SmallIcon( ptr->icon() ) );
	}

	KDevPCSImporter* importer()
	{
		return m_importer;
	}

private:
	KDevPCSImporter* m_importer;
};

class CreatePCSDialog::PCSJobData
{
public:
	TQString dbName;
	Catalog * catalog;
	RppDriver * driver;
	TQStringList list;
	TQStringList::iterator it;
	int progress;

	PCSJobData( const TQString & dbName, TQStringList const & fileList ) 
		: dbName( dbName), list( fileList ), it( list.begin() ), progress( 0 )
	{
		catalog = new Catalog;
		catalog->open( dbName );
		catalog->addIndex( "kind" );
		catalog->addIndex( "name" );
		catalog->addIndex( "scope" );
		catalog->addIndex( "fileName" );
		
		driver = new RppDriver( catalog );
	}
	
	~PCSJobData()
	{
		delete driver;
		delete catalog;
	}
};



CreatePCSDialog::CreatePCSDialog( CppSupportPart* part, TQWidget* parent, const char* name, bool modal, WFlags fl )
	: CreatePCSDialogBase( parent, name, modal, fl ), m_part( part ), m_jobData( 0 )
{
	helpButton()->hide();
	
	m_settings = 0;
	importerListView->header() ->hide();

	TDETrader::OfferList lst = TDETrader::self() ->query( "TDevelop/PCSImporter" );
	kdDebug( 9007 ) << "====================> found " << lst.size() << " importers" << endl;

	for ( TDETrader::OfferList::Iterator it = lst.begin(); it != lst.end(); ++it )
	{
		KService::Ptr ptr = *it;

		int error = 0;
		KDevPCSImporter* importer = KParts::ComponentFactory::createInstanceFromService<KDevPCSImporter>( ptr, TQT_TQOBJECT(this), ptr->name().latin1(), TQStringList(), &error );
		if ( importer )
		{
			new PCSListViewItem( ptr, importer, importerListView );
		}
	}

	setNextEnabled( importerPage, false );

	TQHBoxLayout* hbox = new TQHBoxLayout( settingsPage );
	hbox->setAutoAdd( true );

	if ( importerListView->firstChild() )
	{
		importerListView->setSelected( importerListView->firstChild(), true );
		setNextEnabled( importerPage, true );
	}
}

CreatePCSDialog::~CreatePCSDialog()
{}

/*$SPECIALIZATION$*/
void CreatePCSDialog::back()
{
	TQWizard::back();
}

void CreatePCSDialog::next()
{
	TQWizard::next();
}

void CreatePCSDialog::reject()
{
	if ( m_jobData ) {
		m_part->removeCatalog( m_jobData->dbName );
		
		delete m_jobData;
		m_jobData = 0;
	}
	
	TQWizard::reject();
}

void CreatePCSDialog::accept()
{
	delete m_jobData;
	m_jobData = 0;
	
	TQWizard::accept();
}

void CreatePCSDialog::slotSelected( const TQString & )
{
	if ( currentPage() == settingsPage )
	{
		if ( m_settings )
			delete( m_settings );

		KDevPCSImporter* importer = static_cast<PCSListViewItem*>( importerListView->selectedItem() ) ->importer();
		m_settings = importer->createSettingsPage( settingsPage );
		setNextEnabled( currentPage(), false );
		setHelpEnabled( currentPage(), false );
		connect( m_settings, TQT_SIGNAL( enabled( int ) ), this, TQT_SLOT( setNextPageEnabled( int ) ) );

		if ( m_settings )
		{
			setHelpEnabled( m_settings, false );
			m_settings->show();
		}
	}
	else if ( currentPage() == descriptionPage )
	{
		KDevPCSImporter* importer = static_cast<PCSListViewItem*>( importerListView->selectedItem() )->importer();
		filename_edit->setText( importer->dbName() );
	}
	else if ( currentPage() == finalPage )
	{
		setBackEnabled( currentPage(), false );
		setNextEnabled( currentPage(), false );

		KDevPCSImporter* importer = static_cast<PCSListViewItem*>( importerListView->selectedItem() )->importer();
		TQStringList fileList = importer->fileList();
		progressBar->setTotalSteps( fileList.size() );
		progressBar->setPercentageVisible( true );

		TDEStandardDirs *dirs = m_part->instance() ->dirs();

		TQString dbName = dirs->saveLocation( "data", "kdevcppsupport/pcs" ) + KURL::encode_string_no_slash(filename_edit->text()) + ".db";
		kdDebug( 9007 ) << "================================> dbName = " << dbName << endl;

		m_part->removeCatalog( dbName );
		
		m_jobData = new PCSJobData( dbName, fileList );
		TQTimer::singleShot( 0, this, TQT_SLOT(parseNext()) );
	}
}

void CreatePCSDialog::parseNext( )
{
	if ( ! m_jobData ) return;
	
	if ( m_jobData->it == m_jobData->list.end() ) 
	{
		if ( m_jobData->progress > 0 )
		{
			m_part->addCatalog( m_jobData->catalog );
			m_jobData->catalog = 0;
		}
		currentFile->setText("");
		cancelButton()->setEnabled( false );
		
		setFinishEnabled( currentPage(), true );
		
		delete m_jobData;
		m_jobData = 0;
		
		return;
	}
	
	progressBar->setProgress( ++(m_jobData->progress) );
	currentFile->setText( KStringHandler::lsqueeze( *(m_jobData->it), 80 ) );
	
	m_jobData->driver->parseFile( *(m_jobData->it) );
	
	++(m_jobData->it);
	
	TQTimer::singleShot( 0, this, TQT_SLOT(parseNext()) );	
}


void CreatePCSDialog::setNextPageEnabled( int enabled )
{
	setNextEnabled( currentPage(), enabled );
}

void CreatePCSDialog::slotSelectionChanged( TQListViewItem * item )
{
	setNextPageEnabled( item != 0 );
}

//kate: indent-mode csands; tab-width 4; space-indent off;