summaryrefslogtreecommitdiffstats
path: root/quanta/project/projectnewgeneral.cpp
blob: fe6030bb6f7c74b4a95abdbe230723e15b1e37a9 (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
/***************************************************************************
                          projectnewgeneral.cpp  -  description
                             -------------------
    begin                : Fri Oct 27 2000
    copyright            : (C) 2000 by Dmitry Poplavsky & Alexander Yakovlev & Eric Laffoon <pdima@users.sourceforge.net,yshurik@penguinpowered.com,sequitur@easystreet.com>
                           (C) 2001-2002 by Andras Mantia <amantia@kde.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.                                   *
 *                                                                         *
 ***************************************************************************/

// qt includes
#include <tqdir.h>
#include <tqevent.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqlineedit.h>
#include <tqpushbutton.h>
#include <tqradiobutton.h>
#include <tqcombobox.h>

// kde includes
#include <kfiledialog.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kurl.h>
#include <kprotocolinfo.h>
#include <tdeversion.h>

//app includes
#include "projectnewgeneral.h"
#include "quantacommon.h"
#include "qextfileinfo.h"

ProjectNewGeneral::ProjectNewGeneral(TQWidget *parent, const char *name )
  : ProjectNewGeneralS(parent,name)
{
  imagelabel->setPixmap( UserIcon("wiznewprjglb") );
  linePrjName->setFocus();

  TQStringList protocols = KProtocolInfo::protocols();
  protocols.sort();
  for ( uint i=0; i<protocols.count(); i++ )
  {
    KURL p;
    p.setProtocol(protocols[i]);
    TQString protocol = protocols[i];
    if ( KProtocolInfo::supportsWriting(p) &&
         KProtocolInfo::supportsMakeDir(p) &&
         KProtocolInfo::supportsDeleting(p) &&
         (protocol != "file" && protocol != "fonts" && protocol != "floppy" && protocol != "newcd" ))
    {
      comboProtocol->insertItem(protocol);
    }
  }
  comboProtocol->setCurrentItem(0);

  slotProtocolChanged(i18n("Local"));

  linePrjTmpl->setText("templates");
  linePrjToolbar->setText("toolbars");

  connect(comboProtocol, TQT_SIGNAL(activated(const TQString&)), TQT_SLOT(slotProtocolChanged(const TQString &)));
  connect( linePrjFile, TQT_SIGNAL(textChanged(const TQString &)),
           this,        TQT_SLOT(slotLinePrjFile(const TQString &)));
  connect( linePrjName, TQT_SIGNAL(textChanged(const TQString &)),
           this,        TQT_SLOT(slotLinePrjFile(const TQString &)));
  connect( linePrjDir,  TQT_SIGNAL(textChanged(const TQString &)),
           this,        TQT_SLOT(slotLinePrjFile(const TQString &)));
  connect( buttonDir,    TQT_SIGNAL(clicked()),
           this,        TQT_SLOT(slotButtonDir()));
  connect( linePrjName, TQT_SIGNAL(textChanged(const TQString &)),
           this,        TQT_SLOT(slotChangeNames(const TQString &)));
  connect( linePrjTmpl, TQT_SIGNAL(textChanged(const TQString &)), TQT_SLOT(slotLinePrjFile(const TQString &)));
  connect( buttonTmpl,  TQT_SIGNAL(clicked()), TQT_SLOT(slotButtonTmpl()));
  connect( linePrjToolbar, TQT_SIGNAL(textChanged(const TQString &)), TQT_SLOT(slotLinePrjFile(const TQString &)));
  connect( buttonToolbar,  TQT_SIGNAL(clicked()), TQT_SLOT(slotButtonToolbar()));

  linePrjTmpl->installEventFilter(this);
  linePrjToolbar->installEventFilter(this);
}

ProjectNewGeneral::~ProjectNewGeneral(){
}

void ProjectNewGeneral::slotButtonDir()
{
   slotLinePrjFile(""); // make sure baseUrl is correct
   KURL url = KFileDialog::getExistingURL(baseUrl.url(), this,
                              i18n("Select Project Folder"));
   if (!url.isEmpty())
   {
     linePrjDir->setText(url.path());
   }
}

void ProjectNewGeneral::slotLinePrjFile( const TQString & )
{

  bool valid = !(linePrjFile->text().isEmpty() ||
                 linePrjName->text().isEmpty() ||
                 linePrjDir ->text().isEmpty() ||
                 linePrjTmpl->text().isEmpty() ||
                 linePrjToolbar->text().isEmpty());
  KURL url;
  TQString s = lineHost->text();
  if (! s.isEmpty())
    url.setHost(s);

  s = lineUser->text();
  if (! s.isEmpty())
    url.setUser(s);
  s = linePasswd->text();
  if (! s.isEmpty())
    url.setPass(s);

  s = linePort->text();
  if (! s.isEmpty())
    url.setPort(linePort->text().toInt());

  url.setProtocol(comboProtocol->currentText());
  if (url.protocol() == i18n("Local")) url.setProtocol("file");
  url.setPath(linePrjDir->text());
  url.adjustPath(1);
  if (!url.path().startsWith("/")) url.setPath("/"+url.path());

  if (url.isValid())
  {
    emit setBaseURL(url);
    baseUrl = url;
    if (baseUrl.isLocalFile())
    {
      s = QExtFileInfo::canonicalPath(baseUrl.path());
      if (!s.isEmpty())
        baseUrl.setPath(s);
    }
  }
  emit enableNextButton( this, valid );
}

void ProjectNewGeneral::slotChangeNames( const TQString &text )
{
  int i;
  TQString fname = text.lower();
  while( (i=fname.find(" ")) >=0 ) fname.remove(i,1);

  linePrjFile->setText( fname+".webprj" );
}

TQString ProjectNewGeneral::type()
{
//  if ( radioCvs  ->isChecked() ) return "CVS";
  if ( radioLocal->isChecked() ) return "Local";
  if ( radioWeb  ->isChecked() ) return "Web";
  return "Local";
}

void ProjectNewGeneral::setMargin(int i)
{
  layout()->setMargin(i);
}

void ProjectNewGeneral::slotButtonTmpl()
{
   slotLinePrjFile(""); // make sure baseUrl is correct
   KURL url = KFileDialog::getExistingURL(baseUrl.url(), this,
                              i18n("Select Project Template Folder"));
   if (!url.isEmpty() && baseUrl.isParentOf(url))
   {
     linePrjTmpl->setText(KURL::relativeURL(baseUrl, url));
   } else
   {
     KMessageBox::sorry(this, i18n("<qt>The project templates must be stored under the main project folder: <br><br><b>%1</b></qt>").arg(baseUrl.prettyURL(0, KURL::StripFileProtocol)));
    }
}

void ProjectNewGeneral::slotButtonToolbar()
{
   slotLinePrjFile(""); // make sure baseUrl is correct
   KURL url = KFileDialog::getExistingURL(baseUrl.url(), this,
                              i18n("Select Project Toolbar & Actions Folder"));
   if (!url.isEmpty() && baseUrl.isParentOf(url))
   {
     linePrjToolbar->setText(KURL::relativeURL(baseUrl, url));
   }
   {
      KMessageBox::sorry(0, i18n("<qt>The project toolbars must be stored under the main project folder: <br><br><b>%1</b></qt>")
                                  .arg(baseUrl.prettyURL(0, KURL::StripFileProtocol)));
   }
}


void ProjectNewGeneral::slotProtocolChanged(const TQString& protocol)
{
 bool status = true;
 if (protocol == i18n("Local"))
 {
   status = false;
 }
 lineHost->setEnabled(status);
 lineUser->setEnabled(status);
 linePasswd->setEnabled(status);
 linePort->setEnabled(status);
 radioWeb->setEnabled(!status);
 slotChangeNames(linePrjName->text());
 if ( !status )
     lineHost->clear();
}

bool ProjectNewGeneral::eventFilter ( TQObject * watched, TQEvent * e )
{
  if (e->type() == TQEvent::FocusOut)
  {
    if (TQT_BASE_OBJECT(watched) == TQT_BASE_OBJECT(linePrjTmpl))
    {
      KURL url = baseUrl;
      QuantaCommon::setUrl(url, linePrjTmpl->text());
      url = QExtFileInfo::toAbsolute(url, baseUrl);
      if (!baseUrl.isParentOf(url))
      {
        KMessageBox::sorry(this,i18n("<qt>The project templates must be stored under the main project folder: <br><br><b>%1</b></qt>").arg(baseUrl.prettyURL(0, KURL::StripFileProtocol)));
        linePrjTmpl->setFocus();
        emit enableNextButton(this, false);
      } else
        emit enableNextButton(this, true);
    } else
    if (TQT_BASE_OBJECT(watched) == TQT_BASE_OBJECT(linePrjToolbar))
    {
      KURL url = baseUrl;
      QuantaCommon::setUrl(url, linePrjToolbar->text());
      url = QExtFileInfo::toAbsolute(url, baseUrl);
      if (!baseUrl.isParentOf(url))
      {
        KMessageBox::sorry(0,i18n("<qt>The project toolbars must be stored under the main project folder: <br><br><b>%1</b></qt>")
                                    .arg(baseUrl.prettyURL(0, KURL::StripFileProtocol)));
        linePrjToolbar->setFocus();
        emit enableNextButton(this, false);
      } else
        emit enableNextButton(this, true);
    }
  }
  return false;  
}

#include "projectnewgeneral.moc"