summaryrefslogtreecommitdiffstats
path: root/languages/php/phpconfigwidget.cpp
blob: 41f3c2fecbdd1b5087379fb4e77c10138d0fde19 (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
#include "domutil.h"
#include <kprocess.h>
#include <klineedit.h>
#include <tqcheckbox.h>
#include <tqmultilineedit.h>
#include <tqcstring.h>
#include <iostream>
#include <tqradiobutton.h>

#include <kfiledialog.h>
#include <kstandarddirs.h>

#include "phpinfodlg.h"
#include "phpconfigwidget.h"
#include "phpconfigdata.h"

using namespace std;

PHPConfigWidget::PHPConfigWidget(PHPConfigData* data,TQWidget* tqparent,  const char* name, WFlags fl )
  : PHPConfigWidgetBase( tqparent, name, fl )
{
   configData = data;
   m_phpInfo = "";

   PHPConfigData::InvocationMode mode = configData->getInvocationMode();

   // page "Invocation"
   if (mode == PHPConfigData::Shell) {
      callPHPDirectly_radio->setChecked(true);
   }

   if (mode == PHPConfigData::Web) {
      callWebserver_radio->setChecked(true);
   }

   // page webserver
   TQString weburl = configData->getWebURL();
   if (weburl.isEmpty())
      weburl = "http://localhost/";
   weburl_edit->setText(weburl); 

   // page shell
   TQString exepath = configData->getPHPExecPath();
   if (exepath.isEmpty()) {
      TQString fiexepath = KStandardDirs::findExe("php");

      if (exepath.isEmpty())
         exepath = "/usr/local/bin/php";
   }

   exe_edit->setText(exepath);

   // page options
   PHPConfigData::StartupFileMode phpStartupFileMode = configData->getStartupFileMode();
   TQString phpStartupFile = configData->getStartupFile();

   useDefaultFile_edit->setText(phpStartupFile);

   if(phpStartupFileMode == PHPConfigData::Current) {
      useCurrentFile_radio->setChecked(true);
   }

   if(phpStartupFileMode == PHPConfigData::Default) {
      useDefaultFile_radio->setChecked(true);
   }

   TQString includepath = configData->getPHPIncludePath();
   include_path_edit->setText(includepath);

   codeCompletion_checkbox->setChecked(configData->getCodeCompletion());
   codeHinting_checkbox->setChecked(configData->getCodeHinting());
   realtimeParsing_checkbox->setChecked(configData->getRealtimeParsing());
}

/*
 *  Destroys the object and frees any allocated resources
 */
PHPConfigWidget::~PHPConfigWidget()
{
  // no need to delete child widgets, TQt does it all for us
}

void PHPConfigWidget::accept()
{
  // invocation
   if (callPHPDirectly_radio->isChecked()){
      configData->setInvocationMode(PHPConfigData::Shell);
   }
   if (callWebserver_radio->isChecked()){
      configData->setInvocationMode(PHPConfigData::Web);
   }

   // webserver
   configData->setWebURL(weburl_edit->text());  

   // shell
   configData->setPHPExePath(exe_edit->text());

   // config
   configData->setPHPIniPath(ini_edit->text());

   // options
   configData->setStartupFile(useDefaultFile_edit->text());

   if (useCurrentFile_radio->isChecked()) {
      configData->setStartupFileMode(PHPConfigData::Current);
   }
   if (useDefaultFile_radio->isChecked()){
      configData->setStartupFileMode(PHPConfigData::Default);
   }

   configData->setPHPIncludePath(include_path_edit->text());
   configData->setCodeCompletion(codeCompletion_checkbox->isChecked());
   configData->setCodeHinting(codeHinting_checkbox->isChecked());
   configData->setRealtimeParsing(realtimeParsing_checkbox->isChecked());

   configData->storeConfig();
}

void PHPConfigWidget::slotZendButtonClicked()
{
   qWarning( "PHPConfigWidgetBase::slotZendButtonClicked(): Not implemented yet!" );
}

void PHPConfigWidget::slotAboutClicked()
{
   qWarning( "PHPConfigWidget::slotAboutClicked()" );
   KShellProcess proc("/bin/sh");
   proc << exe_edit->text();
   proc << "-m";

   connect( &proc, TQT_SIGNAL(receivedStdout (KProcess*, char*, int)),
            this, TQT_SLOT(slotReceivedPHPInfo (KProcess*, char*, int)));
   proc.start(KProcess::Block,KProcess::Stdout);
   PHPInfoDlg dlg(this,"phpinfo",true);
   dlg.php_edit->setText(m_phpInfo);
   dlg.exec();
   m_phpInfo = "";
}

void PHPConfigWidget::slotReceivedPHPInfo (KProcess* /*proc*/, char* buffer, int buflen){
   m_phpInfo += TQCString(buffer,buflen+1);
}

void PHPConfigWidget::slotPHPExeButtonClicked(){
   TQString exe = KFileDialog::getOpenFileName(TQFileInfo(exe_edit->text()).filePath());
   if (!exe.isEmpty()){
      exe_edit->setText(exe);
   }
}

void PHPConfigWidget::slotPHPIniButtonClicked()
{
   TQString file = KFileDialog::getOpenFileName(TQFileInfo(exe_edit->text()).filePath(), TQString("*.ini|INI File (*.ini)"));

   if (!file.isEmpty()){
      ini_edit->setText(file);
   }
}

#include "phpconfigwidget.moc"