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

« back to all changes in this revision

Viewing changes to languages/php/phpsupportpart.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) 2005 by Nicolas Escuder <n.escuder@intra-links.com>
3
 
   Copyright (C) 2001 by smeier@kdevelop.org
4
 
 
5
 
   This library is free software; you can redistribute it and/or
6
 
   modify it under the terms of the GNU Library General Public
7
 
   version 2, License as published by the Free Software Foundation.
8
 
 
9
 
   This library is distributed in the hope that it will be useful,
10
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
   Library General Public License for more details.
13
 
 
14
 
   You should have received a copy of the GNU Library General Public License
15
 
   along with this library; see the file COPYING.LIB.  If not, write to
16
 
   the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
17
 
   Boston, MA 02110-1301, USA.
18
 
*/
19
 
 
20
 
#include "phpsupportpart.h"
21
 
 
22
 
#include <iostream>
23
 
 
24
 
#include <qdir.h>
25
 
#include <qfileinfo.h>
26
 
#include <qpopupmenu.h>
27
 
#include <qprogressbar.h>
28
 
#include <qstringlist.h>
29
 
#include <qtextstream.h>
30
 
#include <qtimer.h>
31
 
#include <qvbox.h>
32
 
#include <qwhatsthis.h>
33
 
#include <qthread.h>
34
 
 
35
 
#include <kaction.h>
36
 
#include <kapplication.h>
37
 
#include <kdebug.h>
38
 
#include <khtmlview.h>
39
 
#include <klocale.h>
40
 
#include <kmessagebox.h>
41
 
#include <kprocess.h>
42
 
#include <kregexp.h>
43
 
#include <kstatusbar.h>
44
 
#include <kparts/browserextension.h>
45
 
 
46
 
#include <kdevcore.h>
47
 
#include <kdevproject.h>
48
 
#include <kdevmainwindow.h>
49
 
#include <kdevpartcontroller.h>
50
 
#include <codemodel.h>
51
 
#include <domutil.h>
52
 
#include <kdevplugininfo.h>
53
 
#include <kiconloader.h>
54
 
 
55
 
#include "phpconfigdata.h"
56
 
#include "phpconfigwidget.h"
57
 
#include "phpcodecompletion.h"
58
 
#include "phpparser.h"
59
 
#include "phpnewclassdlg.h"
60
 
 
61
 
 
62
 
#include "phphtmlview.h"
63
 
#include "phperrorview.h"
64
 
 
65
 
#include "phpsupport_event.h"
66
 
 
67
 
using namespace std;
68
 
 
69
 
static const KDevPluginInfo data("kdevphpsupport");
70
 
K_EXPORT_COMPONENT_FACTORY( libkdevphpsupport, PHPSupportFactory( data ) )
71
 
 
72
 
PHPSupportPart::PHPSupportPart(QObject *parent, const char *name, const QStringList &)
73
 
    : KDevLanguageSupport(&data, parent, name ? name : "PHPSupportPart")
74
 
{
75
 
   m_htmlView = 0;
76
 
   m_parser = 0;
77
 
   phpExeProc = 0;
78
 
   setInstance(PHPSupportFactory::instance());
79
 
 
80
 
   setXMLFile("kdevphpsupport.rc");
81
 
 
82
 
   connect( core(), SIGNAL(projectOpened()), this, SLOT(projectOpened()) );
83
 
   connect( core(), SIGNAL(projectClosed()), this, SLOT(projectClosed()) );
84
 
   connect( partController(), SIGNAL(savedFile(const KURL&)),
85
 
            this, SLOT(savedFile(const KURL&)) );
86
 
   connect( core(), SIGNAL(projectConfigWidget(KDialogBase*)),
87
 
            this, SLOT(projectConfigWidget(KDialogBase*)) );
88
 
 
89
 
   KAction *action;
90
 
 
91
 
   action = new KAction( i18n("&Run"), "exec",Key_F9,
92
 
   this, SLOT(slotRun()),
93
 
   actionCollection(), "build_execute" );
94
 
   action->setToolTip(i18n("Run"));
95
 
   action->setWhatsThis(i18n("<b>Run</b><p>Executes script on a terminal or a webserver."));
96
 
 
97
 
   action = new KAction( i18n("&New Class..."),0,
98
 
   this, SLOT(slotNewClass()),
99
 
   actionCollection(), "project_new_class" );
100
 
   action->setToolTip(i18n("New class"));
101
 
   action->setWhatsThis(i18n("<b>New class</b><p>Runs New Class wizard."));
102
 
 
103
 
   m_phpErrorView = new PHPErrorView(this, 0, "phpErrorWidget");
104
 
   m_phpErrorView->setIcon( SmallIcon("info") );
105
 
 
106
 
   QWhatsThis::add(m_phpErrorView, i18n("<b>PHP problems</b><p>This view shows PHP parser warnings, errors, and fatal errors."));
107
 
   mainWindow()->embedOutputView(m_phpErrorView, i18n("Problems"), i18n("Problems"));
108
 
 
109
 
   phpExeProc = new KShellProcess("/bin/sh");
110
 
   connect( phpExeProc, SIGNAL(receivedStdout (KProcess*, char*, int)),
111
 
            this, SLOT(slotReceivedPHPExeStdout (KProcess*, char*, int)));
112
 
   connect( phpExeProc, SIGNAL(receivedStderr (KProcess*, char*, int)),
113
 
            this, SLOT(slotReceivedPHPExeStderr (KProcess*, char*, int)));
114
 
   connect( phpExeProc, SIGNAL(processExited(KProcess*)),
115
 
            this, SLOT(slotPHPExeExited(KProcess*)));
116
 
 
117
 
   m_htmlView = new PHPHTMLView(this);
118
 
   mainWindow()->embedOutputView(m_htmlView->view(), i18n("PHP"), i18n("PHP"));
119
 
   connect( m_htmlView,  SIGNAL(started(KIO::Job*)),
120
 
            this, SLOT(slotWebJobStarted(KIO::Job*)));
121
 
 
122
 
   configData = new PHPConfigData(projectDom());
123
 
   connect( configData,  SIGNAL(configStored()),
124
 
            this, SLOT(slotConfigStored()));
125
 
 
126
 
   m_codeCompletion = new  PHPCodeCompletion(this, configData);
127
 
 
128
 
   new KAction(i18n("Complete Text"), CTRL+Key_Space, m_codeCompletion, SLOT(cursorPositionChanged()), actionCollection(), "edit_complete_text");
129
 
 
130
 
   connect( partController(), SIGNAL(activePartChanged(KParts::Part*)),
131
 
            this, SLOT(slotActivePartChanged(KParts::Part *)));
132
 
   connect( this, SIGNAL(fileParsed( PHPFile* )), this, SLOT(slotfileParsed( PHPFile* )));
133
 
}
134
 
 
135
 
PHPSupportPart::~PHPSupportPart()
136
 
{
137
 
   LastClass = NULL;
138
 
   LastMethod = NULL;
139
 
   LastVariable = NULL;
140
 
 
141
 
   if ( m_parser ) {
142
 
      m_parser->close() ;
143
 
      delete( m_parser );
144
 
      m_parser = NULL;
145
 
   }
146
 
 
147
 
   if ( m_phpErrorView ) {
148
 
      mainWindow()->removeView( m_phpErrorView );
149
 
      delete( m_phpErrorView );
150
 
      m_phpErrorView = NULL;
151
 
   }
152
 
 
153
 
   kdDebug(9018) << "remove codeCompletition" << endl;
154
 
   if ( m_codeCompletion )
155
 
      delete( m_codeCompletion );
156
 
 
157
 
   kdDebug(9018) << "remove configData" << endl;
158
 
   if ( configData )
159
 
      delete( configData );
160
 
 
161
 
   if ( m_htmlView ) {
162
 
      kdDebug(9018) << "remove htmlView" << endl;
163
 
      mainWindow()->removeView( m_htmlView->view() );
164
 
      delete( m_htmlView );
165
 
      m_htmlView = NULL;
166
 
   }
167
 
 
168
 
   kdDebug(9018) << "remove phpExec" << endl;
169
 
   if ( phpExeProc )
170
 
      delete( phpExeProc );
171
 
 
172
 
   kdDebug(9018) << "finish" << endl;
173
 
}
174
 
 
175
 
void PHPSupportPart::slotActivePartChanged(KParts::Part *part) {
176
 
   kdDebug(9018) << "enter slotActivePartChanged" << endl;
177
 
   if (!part || !part->widget())
178
 
      return;
179
 
   m_editInterface = dynamic_cast<KTextEditor::EditInterface*>(part);
180
 
   if (m_editInterface) { // connect to the editor
181
 
      disconnect(part, 0, this, 0 ); // to make sure that it is't connected twice
182
 
      if (configData->getRealtimeParsing()) {
183
 
         connect(part,SIGNAL(textChanged()),this,SLOT(slotTextChanged()));
184
 
      }
185
 
      m_codeCompletion->setActiveEditorPart(part);
186
 
   }
187
 
   kdDebug(9018) << "exit slotActivePartChanged" << endl;
188
 
}
189
 
 
190
 
void PHPSupportPart::slotTextChanged() {
191
 
   kdDebug(9018) << "enter text changed" << endl;
192
 
 
193
 
   KParts::ReadOnlyPart *ro_part = dynamic_cast<KParts::ReadOnlyPart*>(partController()->activePart());
194
 
   if (!ro_part)
195
 
      return;
196
 
 
197
 
   QString fileName = ro_part->url().directory() + "/" + ro_part->url().fileName();
198
 
 
199
 
   if (m_parser) {
200
 
      if (m_parser->hasFile( fileName ))
201
 
         m_parser->reparseFile( fileName );
202
 
   }
203
 
}
204
 
 
205
 
void PHPSupportPart::slotConfigStored() {
206
 
   // fake a changing, this will read the configuration again and install the connects
207
 
   slotActivePartChanged(partController()->activePart());
208
 
}
209
 
 
210
 
void PHPSupportPart::projectConfigWidget(KDialogBase *dlg) {
211
 
   QVBox *vbox = dlg->addVBoxPage(i18n( "PHP Specific" ), i18n("PHP Settings"), BarIcon( "source", KIcon::SizeMedium ));
212
 
   PHPConfigWidget* w = new PHPConfigWidget(configData,vbox, "php config widget");
213
 
   connect( dlg, SIGNAL(okClicked()), w, SLOT(accept()) );
214
 
}
215
 
 
216
 
void PHPSupportPart::slotNewClass() {
217
 
   QStringList classNames = sortedNameList( codeModel()->globalNamespace()->classList() );
218
 
   PHPNewClassDlg dlg(classNames,project()->projectDirectory());
219
 
   dlg.exec();
220
 
 }
221
 
 
222
 
void PHPSupportPart::slotRun() {
223
 
   configData = new PHPConfigData(projectDom());
224
 
   if (validateConfig()) {
225
 
      mainWindow()->raiseView(m_htmlView->view());
226
 
      PHPConfigData::InvocationMode mode = configData->getInvocationMode() ;
227
 
      if (mode == PHPConfigData::Web) {
228
 
         executeOnWebserver();
229
 
      }
230
 
      else if (mode == PHPConfigData::Shell) {
231
 
         executeInTerminal();
232
 
      }
233
 
   }
234
 
}
235
 
 
236
 
bool PHPSupportPart::validateConfig() {
237
 
   if (!configData->validateConfig()) {
238
 
      KMessageBox::information(0,i18n("There is no configuration for executing a PHP file.\nPlease set the correct values in the next dialog."));
239
 
      KDialogBase dlg(KDialogBase::TreeList, i18n("Customize PHP Mode"),
240
 
                     KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, 0,
241
 
                     "php config dialog");
242
 
 
243
 
      QVBox *vbox = dlg.addVBoxPage(i18n("PHP Settings"));
244
 
      PHPConfigWidget* w = new PHPConfigWidget(configData,vbox, "php config widget");
245
 
      connect( &dlg, SIGNAL(okClicked()), w, SLOT(accept()) );
246
 
      dlg.exec();
247
 
   }
248
 
   if (configData->validateConfig()) {
249
 
      return true;
250
 
   }
251
 
   return false;
252
 
}
253
 
 
254
 
void PHPSupportPart::executeOnWebserver() {
255
 
   // Save all files once
256
 
   if (partController()->saveAllFiles()==false)
257
 
      return; //user cancelled
258
 
 
259
 
   // Figure out the name of the remote file
260
 
   QString weburl = configData->getWebURL();
261
 
   QString file = getExecuteFile();
262
 
 
263
 
   // Force KHTMLPart to reload the page
264
 
   KParts::BrowserExtension* be = m_htmlView->browserExtension();
265
 
   if (be) {
266
 
      KParts::URLArgs urlArgs( be->urlArgs() );
267
 
      urlArgs.reload = true;
268
 
      be->setURLArgs( urlArgs );
269
 
   }
270
 
 
271
 
   // Acutally do the request
272
 
   m_phpExeOutput="";
273
 
   m_htmlView->openURL(KURL(weburl + file));
274
 
   m_htmlView->show();
275
 
}
276
 
 
277
 
QString PHPSupportPart::getExecuteFile() {
278
 
   QString file;
279
 
   PHPConfigData::StartupFileMode mode = configData->getStartupFileMode();
280
 
 
281
 
   QString weburl = configData->getWebURL();
282
 
   if (mode == PHPConfigData::Current) {
283
 
      KParts::ReadOnlyPart *ro_part = dynamic_cast<KParts::ReadOnlyPart*>(partController()->activePart());
284
 
      if (ro_part) {
285
 
         if ( configData->getInvocationMode() == PHPConfigData::Web )
286
 
            file = URLUtil::relativePath( project()->projectDirectory(), ro_part->url().path() );
287
 
         else
288
 
            file = ro_part->url().path();
289
 
      }
290
 
   }
291
 
   if (mode == PHPConfigData::Default) {
292
 
      file = configData->getStartupFile();
293
 
   }
294
 
   return file;
295
 
}
296
 
 
297
 
void PHPSupportPart::slotWebJobStarted(KIO::Job* job) {
298
 
   if (job && job->className() == QString("KIO::TransferJob")) {
299
 
      kdDebug(9018) << endl << "job started" << job->progressId();
300
 
      KIO::TransferJob *tjob = static_cast<KIO::TransferJob*>(job);
301
 
      connect( tjob,  SIGNAL(data(KIO::Job*, const QByteArray&)),
302
 
               this, SLOT(slotWebData(KIO::Job*, const QByteArray&)));
303
 
      connect( tjob,  SIGNAL(result(KIO::Job*)),
304
 
               this, SLOT(slotWebResult(KIO::Job*)));
305
 
   }
306
 
}
307
 
 
308
 
void PHPSupportPart::slotWebData(KIO::Job* /*job*/,const QByteArray& data) {
309
 
   kdDebug(9018) << "slotWebData()" << endl;
310
 
   QString strData(data);
311
 
   m_phpExeOutput += strData;
312
 
}
313
 
 
314
 
void PHPSupportPart::slotWebResult(KIO::Job* /*job*/) {
315
 
   kdDebug(9018) << "slotWebResult()" << endl;
316
 
   QString file = getExecuteFile();
317
 
   PHPFile *pfile = new PHPFile(this, file);
318
 
   pfile->ParseStdout(m_phpExeOutput);
319
 
   delete pfile;
320
 
}
321
 
 
322
 
void PHPSupportPart::executeInTerminal() {
323
 
   kdDebug(9018) << "slotExecuteInTerminal()" << endl;
324
 
 
325
 
   // Save all files once
326
 
   if (partController()->saveAllFiles()==false)
327
 
       return; //user cancelled
328
 
 
329
 
   QString file = getExecuteFile();
330
 
 
331
 
   if (m_htmlView == 0) {
332
 
      m_htmlView = new PHPHTMLView(this);
333
 
      mainWindow()->embedOutputView(m_htmlView->view(), i18n("PHP"), i18n("PHP") );
334
 
   }
335
 
 
336
 
   m_htmlView->show();
337
 
   m_htmlView->begin();
338
 
 
339
 
   m_phpExeOutput = "";
340
 
   phpExeProc->clearArguments();
341
 
   *phpExeProc << configData->getPHPExecPath();
342
 
   *phpExeProc << "-f";
343
 
 
344
 
   *phpExeProc << KShellProcess::quote(file);
345
 
   kdDebug(9018) << "" << file.latin1() << endl;
346
 
   phpExeProc->start(KProcess::NotifyOnExit,KProcess::All);
347
 
 
348
 
   //    core()->gotoDocumentationFile(KURL("http://www.php.net"));
349
 
}
350
 
 
351
 
void PHPSupportPart::slotReceivedPHPExeStdout (KProcess* /*proc*/, char* buffer, int buflen) {
352
 
   kdDebug(9018) << "slotPHPExeStdout()" << endl;
353
 
   m_phpExeOutput += QString::fromLocal8Bit(buffer,buflen+1);
354
 
 
355
 
   QString buf = buffer;
356
 
   if (configData->getInvocationMode() == PHPConfigData::Shell)
357
 
     buf.replace("\n", "<br>");
358
 
    m_htmlView->write(buf);
359
 
}
360
 
 
361
 
void PHPSupportPart::slotReceivedPHPExeStderr (KProcess* /*proc*/, char* buffer, int buflen) {
362
 
   kdDebug(9018) << "slotPHPExeStderr()" << endl;
363
 
   m_phpExeOutput += QString::fromLocal8Bit(buffer,buflen+1);
364
 
 
365
 
   QString buf = buffer;
366
 
   if (configData->getInvocationMode() == PHPConfigData::Shell)
367
 
      buf.replace("\n", "<br>");
368
 
   m_htmlView->write(buf);
369
 
}
370
 
 
371
 
void PHPSupportPart::slotPHPExeExited (KProcess* /*proc*/) {
372
 
   kdDebug(9018) << "slotPHPExeExited()" << endl;
373
 
   m_htmlView->end();
374
 
   QString file = getExecuteFile();
375
 
   PHPFile *pfile = new PHPFile(this, file);
376
 
   pfile->ParseStdout(m_phpExeOutput);
377
 
   delete pfile;
378
 
}
379
 
 
380
 
void PHPSupportPart::projectOpened()
381
 
{
382
 
    kdDebug(9018) << "projectOpened()" << endl;
383
 
 
384
 
    connect( project(), SIGNAL(addedFilesToProject(const QStringList &)),
385
 
             this, SLOT(addedFilesToProject(const QStringList &)) );
386
 
    connect( project(), SIGNAL(removedFilesFromProject(const QStringList &)),
387
 
             this, SLOT(removedFilesFromProject(const QStringList &)) );
388
 
 
389
 
    if (!m_parser) {
390
 
       m_parser = new  PHPParser( this );
391
 
       m_parser->start();
392
 
    }
393
 
 
394
 
    // We want to parse only after all components have been
395
 
    // properly initialized
396
 
    QTimer::singleShot(500, this, SLOT( initialParse() ) );
397
 
}
398
 
 
399
 
void PHPSupportPart::initialParse( )
400
 
{
401
 
        // For debugging
402
 
        if ( !project( ) )
403
 
        {
404
 
                // messagebox ?
405
 
                kdDebug( 9018 ) << "No project" << endl;
406
 
                return ;
407
 
        }
408
 
 
409
 
        parseProject( );
410
 
        return ;
411
 
}
412
 
 
413
 
void PHPSupportPart::projectClosed()
414
 
{
415
 
   kdDebug(9018) << "projectClosed()" << endl;
416
 
 
417
 
   if (m_parser) {
418
 
      m_parser->close() ;
419
 
      delete( m_parser );
420
 
      m_parser = 0;
421
 
   }
422
 
}
423
 
 
424
 
bool PHPSupportPart::parseProject()
425
 
{
426
 
   kdDebug(9018) << "parseProject()" << endl;
427
 
   mainWindow() ->statusBar() ->message( i18n( "Updating..." ) );
428
 
 
429
 
   kapp->setOverrideCursor( waitCursor );
430
 
 
431
 
   _jd = new JobData;
432
 
 
433
 
   _jd->files = project()->allFiles();
434
 
 
435
 
   QProgressBar* bar = new QProgressBar( _jd->files.count( ), mainWindow( ) ->statusBar( ) );
436
 
   bar->setMinimumWidth( 120 );
437
 
   bar->setCenterIndicator( true );
438
 
   mainWindow()->statusBar()->addWidget( bar );
439
 
   bar->show();
440
 
 
441
 
   _jd->progressBar = bar;
442
 
   _jd->it = _jd->files.begin();
443
 
   _jd->dir.setPath( project()->projectDirectory() );
444
 
 
445
 
   QTimer::singleShot( 0, this, SLOT( slotParseFiles() ) );
446
 
   return TRUE;
447
 
}
448
 
 
449
 
void PHPSupportPart::slotParseFiles()
450
 
{
451
 
   kdDebug(9018) << "slotParseFiles()" << endl;
452
 
 
453
 
   kapp->lock();
454
 
 
455
 
   if ( _jd->it != _jd->files.end() )
456
 
   {
457
 
      _jd->progressBar->setProgress( _jd->progressBar->progress() + 1 );
458
 
 
459
 
      QFileInfo fileInfo( _jd->dir, *( _jd->it ) );
460
 
 
461
 
      if ( fileInfo.exists() && fileInfo.isFile() && fileInfo.isReadable() )
462
 
      {
463
 
         QString absFilePath = URLUtil::canonicalPath( fileInfo.absFilePath() );
464
 
 
465
 
//         if ( isValidSource( absFilePath ) )
466
 
         {
467
 
            if (m_parser)
468
 
               m_parser->addFile( absFilePath );
469
 
         }
470
 
 
471
 
         ++( _jd->it );
472
 
      }
473
 
      QTimer::singleShot( 0, this, SLOT( slotParseFiles() ) );
474
 
   }
475
 
   else // finished or interrupted
476
 
   {
477
 
      kapp->restoreOverrideCursor();
478
 
      mainWindow()->statusBar()->removeWidget( _jd->progressBar );
479
 
      mainWindow()->statusBar()->message( i18n( "Done" ), 2000 );
480
 
 
481
 
      emit updatedSourceInfo();
482
 
      if (m_parser)
483
 
         m_parser->startParse();
484
 
 
485
 
      delete _jd;
486
 
      _jd = 0;
487
 
   }
488
 
 
489
 
   kapp->unlock();
490
 
}
491
 
 
492
 
void PHPSupportPart::addedFilesToProject(const QStringList &fileList)
493
 
{
494
 
   kdDebug(9018) << "addedFilesToProject()" << endl;
495
 
 
496
 
   QStringList::ConstIterator it;
497
 
 
498
 
   for ( it = fileList.begin(); it != fileList.end(); ++it )
499
 
   {
500
 
      QFileInfo fileInfo( project()->projectDirectory(), *it );
501
 
      if (m_parser) {
502
 
         m_parser->addFile( fileInfo.absFilePath() );
503
 
         emit addedSourceInfo( fileInfo.absFilePath() );
504
 
      }
505
 
   }
506
 
}
507
 
 
508
 
void PHPSupportPart::removedFilesFromProject(const QStringList &fileList)
509
 
{
510
 
   kdDebug(9018) << "removedFilesFromProject()" << endl;
511
 
 
512
 
   QStringList::ConstIterator it;
513
 
 
514
 
   for ( it = fileList.begin(); it != fileList.end(); ++it )
515
 
   {
516
 
      QFileInfo fileInfo( project()->projectDirectory(), *it );
517
 
      QString path = fileInfo.absFilePath();
518
 
      if ( codeModel()->hasFile(path) ) {
519
 
         emit aboutToRemoveSourceInfo( path );
520
 
         codeModel()->removeFile( codeModel()->fileByName(path) );
521
 
      }
522
 
   }
523
 
}
524
 
 
525
 
void PHPSupportPart::savedFile(const KURL &fileName)
526
 
{
527
 
   kdDebug(9018) << "savedFile()" << fileName.fileName() << endl;
528
 
/// @fixme when activated could cause stop
529
 
/*
530
 
   if (m_parser) {
531
 
      if (m_parser->hasFile( fileName.path() )) {
532
 
         m_parser->reparseFile( fileName.path() );
533
 
      }
534
 
   }
535
 
*/
536
 
}
537
 
 
538
 
QString PHPSupportPart::getIncludePath()
539
 
{
540
 
   return configData->getPHPIncludePath();
541
 
}
542
 
 
543
 
QString PHPSupportPart::getExePath()
544
 
{
545
 
   return configData->getPHPExecPath();
546
 
}
547
 
 
548
 
KDevLanguageSupport::Features PHPSupportPart::features()
549
 
{
550
 
   return Features(Classes | Functions);
551
 
}
552
 
 
553
 
KMimeType::List PHPSupportPart::mimeTypes( )
554
 
{
555
 
   KMimeType::List list;
556
 
   KMimeType::Ptr mime = KMimeType::mimeType( "application/x-php" );
557
 
   if ( mime )
558
 
      list << mime;
559
 
 
560
 
   mime = KMimeType::mimeType( "text/plain" );
561
 
   if ( mime )
562
 
      list << mime;
563
 
   return list;
564
 
}
565
 
 
566
 
void PHPSupportPart::customEvent( QCustomEvent* ev )
567
 
{
568
 
//   kdDebug(9018) << "phpSupportPart::customEvent(" << ev->type() << ") " << QThread::currentThread() << endl;
569
 
 
570
 
   if ( ev->type() < Event_AddFile || ev->type() > Event_AddFixme )
571
 
      return;
572
 
 
573
 
   kapp->lock();
574
 
 
575
 
   FileParseEvent* event = (FileParseEvent*) ev;
576
 
   NamespaceDom ns = codeModel()->globalNamespace();
577
 
   FileDom m_file = codeModel()->fileByName( event->fileName() );
578
 
 
579
 
   if (!m_file) {
580
 
      m_file = codeModel()->create<FileModel>();
581
 
      m_file->setName( event->fileName() );
582
 
      codeModel()->addFile( m_file );
583
 
   }
584
 
 
585
 
   switch (int(ev->type())) {
586
 
      case Event_AddFile:
587
 
         m_parser->addFile( event->fileName() );
588
 
      break;
589
 
 
590
 
      case Event_StartParse:
591
 
//         kdDebug(9018) << "StartParse " << event->fileName() << endl;
592
 
         LastClass = NULL;
593
 
         LastMethod = NULL;
594
 
         LastVariable = NULL;
595
 
         if ( codeModel()->hasFile( event->fileName() ) ) {
596
 
            emit aboutToRemoveSourceInfo( event->fileName() );
597
 
            codeModel()->removeFile( codeModel()->fileByName( event->fileName() ) );
598
 
            emit removedSourceInfo( event->fileName() );
599
 
         }
600
 
         ErrorView()->removeAllProblems( event->fileName() );
601
 
      break;
602
 
 
603
 
      case Event_AddClass:
604
 
      {
605
 
//         kdDebug(9018) << "AddClass " << event->name() << endl;
606
 
         ClassDom nClass = codeModel()->create<ClassModel>();
607
 
         nClass->setFileName( event->fileName() );
608
 
         nClass->setName( event->name() );
609
 
         nClass->setStartPosition( event->posititon(), 0);
610
 
 
611
 
         m_file->addClass( nClass );
612
 
         if ( event->arguments().isEmpty() != TRUE )
613
 
            nClass->addBaseClass( event->arguments() );
614
 
 
615
 
         ns->addClass( nClass );
616
 
         LastClass = nClass;
617
 
      }
618
 
      break;
619
 
 
620
 
      case Event_CloseClass:
621
 
         if ( LastClass != NULL ) {
622
 
//            kdDebug(9018) << "CloseClass " << LastClass->name() << endl;
623
 
            LastClass->setEndPosition( event->posititon(), 0 );
624
 
            LastClass = NULL;
625
 
            LastMethod = NULL;
626
 
            LastVariable = NULL;
627
 
         }
628
 
      break;
629
 
 
630
 
      case Event_AddFunction:
631
 
      {
632
 
//         kdDebug(9018) << "AddFunction " << event->name() << endl;
633
 
         FunctionDom nMethod = codeModel()->create<FunctionModel>();
634
 
         nMethod->setFileName( event->fileName() );
635
 
         nMethod->setName( event->name() );
636
 
         nMethod->setStartPosition( event->posititon(), 0 );
637
 
 
638
 
         ArgumentDom nArgument;
639
 
         nArgument = codeModel()->create<ArgumentModel>();
640
 
         nArgument->setType(event->arguments().stripWhiteSpace().local8Bit());
641
 
         nMethod->addArgument( nArgument );
642
 
 
643
 
         if (LastClass != NULL) {
644
 
            LastClass->addFunction(nMethod);
645
 
         } else {
646
 
            ns->addFunction(nMethod);
647
 
         }
648
 
         LastMethod = nMethod;
649
 
      }
650
 
      break;
651
 
 
652
 
      case Event_SetFunction:
653
 
         if ( LastMethod != NULL ) {
654
 
//            kdDebug(9018) << "SetFunction " << LastMethod->name() << " " << event->name() << endl;
655
 
            if ( event->name() == "static" )
656
 
               LastMethod->setStatic(true);
657
 
            else if ( event->name() == "abstract" )
658
 
               LastMethod->setAbstract(true);
659
 
            else if ( event->name() == "private" )
660
 
               LastMethod->setAccess(FunctionModel::Private);
661
 
            else if ( event->name() == "public" )
662
 
               LastMethod->setAccess(FunctionModel::Public);
663
 
            else if ( event->name() == "protected" )
664
 
               LastMethod->setAccess(FunctionModel::Protected);
665
 
            else if ( event->name() == "result" ) {
666
 
               QString ret = "";
667
 
               if (event->arguments().lower() == "$this" && LastClass ) {
668
 
                  ret = LastClass->name();
669
 
               }
670
 
               LastMethod->setResultType(ret);
671
 
            }
672
 
         }
673
 
      break;
674
 
 
675
 
      case Event_CloseFunction:
676
 
         if ( LastMethod != NULL ) {
677
 
//            kdDebug(9018) << "CloseFunction " << LastMethod->name() << endl;
678
 
            LastMethod->setEndPosition( event->posititon(), 0 );
679
 
            LastMethod = NULL;
680
 
            LastVariable = NULL;
681
 
         }
682
 
      break;
683
 
 
684
 
      case Event_AddVariable:
685
 
      {
686
 
         VariableDom nVariable = codeModel()->create<VariableModel>();
687
 
 
688
 
         nVariable->setFileName( event->fileName() );
689
 
         nVariable->setName( event->name() );
690
 
         nVariable->setStartPosition( event->posititon(), 0 );
691
 
         nVariable->setAccess(VariableModel::Public);
692
 
 
693
 
         if ( event->arguments().isEmpty() != TRUE )
694
 
            nVariable->setType( event->arguments() );
695
 
 
696
 
         if ( LastClass != NULL && ( LastMethod == NULL || event->global() == TRUE ) ) {
697
 
//               kdDebug(9018) << "AddVariable To Class " << LastClass->name() << " " << nVariable->name() << endl;
698
 
            LastClass->addVariable(nVariable);
699
 
         } else {
700
 
            if ( LastMethod != NULL ) {
701
 
               kdDebug(9018) << "AddVariable " << LastMethod->name() << " " << nVariable->name() << endl;
702
 
            } else {
703
 
               ns->addVariable(nVariable);
704
 
            }
705
 
         }
706
 
         LastVariable = nVariable;
707
 
      }
708
 
      break;
709
 
 
710
 
      case Event_SetVariable:
711
 
         if ( LastVariable != NULL ) {
712
 
//            kdDebug(9018) << "SetVariable " << LastVariable->name() << " " << event->arguments() << endl;
713
 
            if ( event->arguments() == "static" )
714
 
               LastVariable->setStatic(true);
715
 
            else if ( event->arguments() == "private" )
716
 
               LastVariable->setAccess(FunctionModel::Private);
717
 
            else if ( event->arguments() == "public" )
718
 
               LastVariable->setAccess(FunctionModel::Public);
719
 
            else if ( event->arguments() == "protected" )
720
 
               LastVariable->setAccess(FunctionModel::Protected);
721
 
         }
722
 
      break;
723
 
 
724
 
      case Event_AddTodo:
725
 
         ErrorView()->reportProblem(Todo, event->fileName(), event->posititon(), event->arguments());
726
 
      break;
727
 
 
728
 
      case Event_AddFixme:
729
 
         ErrorView()->reportProblem(Fixme, event->fileName(), event->posititon(), event->arguments());
730
 
      break;
731
 
 
732
 
      case Event_EndParse:
733
 
//         kdDebug(9018) << "EndParse " << event->fileName() << endl;
734
 
         emit addedSourceInfo( event->fileName() );
735
 
      break;
736
 
 
737
 
   }
738
 
 
739
 
   kapp->unlock();
740
 
   kapp->processEvents();
741
 
}
742
 
 
743
 
PHPErrorView *PHPSupportPart::ErrorView( ) {
744
 
   return m_phpErrorView;
745
 
}
746
 
 
747
 
PHPParser *PHPSupportPart::Parser( ) {
748
 
   return m_parser;
749
 
}
750
 
 
751
 
#include "phpsupportpart.moc"