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
|
/***************************************************************************
projectnewweb.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) 2002, 2003 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 <tqlabel.h>
#include <tqlineedit.h>
#include <tqpushbutton.h>
#include <tqstringlist.h>
#include <tqlistview.h>
#include <tqfileinfo.h>
#include <tqcombobox.h>
// kde includes
#include <klocale.h>
#include <kprocess.h>
#include <kiconloader.h>
#include <kio/job.h>
#include <kmessagebox.h>
#include <kled.h>
// app includes
#include "projectnewweb.h"
#include "qextfileinfo.h"
#include "quantacommon.h"
#include "uploadtreeview.h"
ProjectNewWeb::ProjectNewWeb(TQWidget *parent, const char *name )
: ProjectNewWebS(parent,name)
{
button->setEnabled(false);
siteUrl->setFocus();
imagelabel->setPixmap( UserIcon("wiznewprjweb") );
listView->removeColumn(1);
listView->removeColumn(1);
listView->removeColumn(1);
connect( commandLine, TQT_SIGNAL(textChanged(const TQString&)),
this, TQT_SLOT (enableStart(const TQString&)));
connect( siteUrl, TQT_SIGNAL(textChanged(const TQString&)),
this, TQT_SLOT (setCommandL(const TQString&)));
connect( button, TQT_SIGNAL(clicked()),
this, TQT_SLOT (slotStart()));
connect( protocolCombo,TQT_SIGNAL(highlighted(const TQString&)),
this, TQT_SLOT (setProtocol(const TQString&)));
start = false;
KLed1->setState(KLed::Off);
KLed2->setState(KLed::Off);
}
ProjectNewWeb::~ProjectNewWeb(){
}
void ProjectNewWeb::enableStart(const TQString&)
{
if ( !commandLine->text().isEmpty() ) button->setEnabled(true);
else button->setEnabled(false);
}
void ProjectNewWeb::setCommandL(const TQString& url)
{
TQString siteurl = url;
commandLine->setText("wget -c -np -r --level=5 -nH "+ protocolCombo->currentText().lower()+ "://"+siteurl);
}
/** No descriptions */
void ProjectNewWeb::setProtocol(const TQString& protocol)
{
commandLine->setText("wget -c -np -r --level=5 -nH "+ protocol.lower()+ "://"+siteUrl->text());
}
void ProjectNewWeb::setBaseURL(const KURL& a_baseURL)
{
baseURL = a_baseURL;
baseURL.adjustPath(1);
}
void ProjectNewWeb::slotStart()
{
if ( !start )
{
emit enableMessagesWidget();
if (QExtFileInfo::createDir(baseURL, this))
{
if (baseURL.protocol() == "file")
{
chdir( baseURL.path(1).ascii() );
proc = new KProcess();
proc ->clearArguments();
TQStringList list = TQStringList::split (" ", commandLine->text());
for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it )
{
*proc << *it;
}
connect( proc, TQT_SIGNAL(receivedStdout( KProcess*,char*,int)), this,
TQT_SLOT( slotGetWgetOutput(KProcess*,char*,int)));
connect( proc, TQT_SIGNAL(receivedStderr( KProcess*,char*,int)), this,
TQT_SLOT( slotGetWgetOutput(KProcess*,char*,int)));
connect( proc, TQT_SIGNAL(processExited( KProcess *)), this,
TQT_SLOT( slotGetWgetExited(KProcess *)));
if (proc->start(KProcess::NotifyOnExit, KProcess::AllOutput))
{
start = true;
button->setText( i18n("Stop") );
emit enableNextButton((TQWidget *)this->parent(),false);
} else
{
KMessageBox::error(this, i18n("There was an error while trying to run the \"wget\" application.\
Check first that it is present on your system and that it is in your PATH."));
delete proc;
}
} else
{
KMessageBox::sorry(this,i18n("This feature is available only if the project lies on a local disk."));
start = false;
button->setText( i18n("Start") );
emit enableNextButton((TQWidget *)this->parent(),true);
}
} else
{
QuantaCommon::dirCreationError(this, baseURL);
start = false;
button->setText( i18n("Start") );
emit enableNextButton((TQWidget *)this->parent(),true);
}
} else {
// STOPPING !!!
delete proc;
start = false;
button->setText( i18n("Start") );
emit enableNextButton((TQWidget *)this->parent(),true);
}
}
void ProjectNewWeb::slotGetWgetExited(KProcess*)
{
KLed2->setState(KLed::Off);
KLed1->setState(KLed::Off);
start = false;
button->setText( i18n("Start") );
emit messages(i18n("wget finished...\n"));
emit enableNextButton((TQWidget *)this->parent(),true);
}
void ProjectNewWeb::slotGetWgetOutput(KProcess *, char *buffer, int buflen)
{
TQString output = buffer;
output = output.left( buflen );
emit messages(output);
int pos;
TQString basePath = baseURL.path(1);
while ( (pos = output.find("saved")) != -1 )
{
if (KLed1->state() == KLed::Off)
{
KLed1->setState(KLed::On);
KLed2->setState(KLed::Off);
} else
{
KLed2->setState(KLed::On);
KLed1->setState(KLed::Off);
}
int begName = output.findRev('`',pos);
if ( begName == -1 ) {
output = output.remove(0,pos+1);
continue;
}
int endName = output.find('\'',begName);
if ( endName == -1 || endName > pos ) {
output = output.remove(0,pos+1);
continue;
}
TQString fileName = output.left(endName);
fileName = fileName.right( endName - begName-1);
output = output.remove(0,pos+1);
KURL u = baseURL;
QuantaCommon::setUrl(u, fileName);
listView->addItem(u, KFileItem(KFileItem::Unknown, KFileItem::Unknown, KURL()));
}
}
KURL::List ProjectNewWeb::files()
{
//return fileList;
KURL::List r;
KURL u;
TQListViewItem *item;
TQListViewItemIterator it(listView);
for ( ; it.current(); ++it )
{
item = it.current();
if (dynamic_cast<UploadTreeFolder*>(item))
{
u = dynamic_cast<UploadTreeFolder*>(item)->url();
} else
{
u = dynamic_cast<UploadTreeFile*>(item)->url();
}
if (!u.isEmpty()) r.append(u);
}
return r;
}
void ProjectNewWeb::resizeEvent ( TQResizeEvent *t )
{
ProjectNewWebS::resizeEvent(t);
// listView->setColumnWidth(0,listView->width()-listView->columnWidth(1)-20);
}
#include "projectnewweb.moc"
|