Добавил:
korayakov
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
/*
netFileCopyer
Copyright (C) 2004 Dmitry S. Vasilchenko.
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The GNU GPL is contained in /usr/doc/copyright/GPL on a Debian
system and in the file COPYING in the Linux kernel source.
*/
#include <qapplication.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qspinbox.h>
#include <qlabel.h>
#include <qradiobutton.h>
#include <qlayout.h>
#include <qvbuttongroup.h>
#include <qfiledialog.h>
#include "prepare.h"
#include "ftransfer.h"
PrepareDialog::PrepareDialog(QWidget *parent, const char *name)
: QDialog(parent, name)
{
setCaption(tr("Transfer prepare"));
ipLabel = new QLabel(tr("Remote ip: "), this);
ipEdit = new QLineEdit(this);
ipLabel->setBuddy(ipEdit);
portLabel = new QLabel(tr("Remote port: "), this);
portBox = new QSpinBox(this);
portLabel->setBuddy(portBox);
portBox->setRange(1024,65535);
fileLabel = new QLabel(tr("Select file: "), this);
fileEdit = new QLineEdit(this);
fileEdit->setEnabled(false);
fileLabel->setBuddy(fileEdit);
fileButton = new QPushButton(tr(">>"), this);
startButton = new QPushButton(tr("&Start"), this);
startButton->setDefault(true);
quitButton = new QPushButton(tr("&Quit"), this);
QVButtonGroup *buttonGroup = new QVButtonGroup(this);
sendRButton = new QRadioButton(tr("Send file"), buttonGroup);
sendRButton->setChecked(true);
receiveRButton = new QRadioButton(tr("Receive file"), buttonGroup);
receiveRButton->setChecked(false);
connect(fileButton, SIGNAL(clicked()),
this, SLOT(selectFile()));
connect(sendRButton, SIGNAL(stateChanged( int )),
this, SLOT(checkboxChanged( int )));
connect(receiveRButton, SIGNAL(stateChanged( int )),
this, SLOT(checkboxChanged( int )));
connect(startButton, SIGNAL(clicked()),
this, SLOT(startClicked()));
connect(quitButton, SIGNAL(clicked()),
this, SLOT(close()));
QHBoxLayout *topLeftLayout1 = new QHBoxLayout;
topLeftLayout1->addWidget(ipLabel);
topLeftLayout1->addWidget(ipEdit);
QHBoxLayout *topLeftLayout2 = new QHBoxLayout;
topLeftLayout2->addWidget(portLabel);
topLeftLayout2->addWidget(portBox);
QHBoxLayout *topLeftLayout3 = new QHBoxLayout;
topLeftLayout3->addWidget(fileLabel);
topLeftLayout3->addWidget(fileEdit);
topLeftLayout3->addWidget(fileButton);
QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addLayout(topLeftLayout1);
leftLayout->addLayout(topLeftLayout2);
leftLayout->addWidget(buttonGroup);
leftLayout->addLayout(topLeftLayout3);
QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout->addWidget(startButton);
rightLayout->addWidget(quitButton);
rightLayout->addStretch(1);
QHBoxLayout *mainLayout = new QHBoxLayout(this);
mainLayout->setMargin(11);
mainLayout->setSpacing(6);
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayout);
}
void PrepareDialog::startClicked()
{
if (ipEdit->isEnabled() && ipEdit->text().isEmpty()){
return;
}
QString ip = ipEdit->text();
int port = portBox->value();
if (fileEdit->text().isEmpty()){
return;
}
QString file = fileEdit->text();
if (sendRButton->isChecked()){ /* send */
startSend(ip, port, file);
}
else{ /* receive */
startReceive(ip, port, file);
}
}
void PrepareDialog::selectFile()
{
QFileDialog* fd;
if (sendRButton->isChecked()){ /* select file */
fd = new QFileDialog( this, "file select dialog", TRUE );
fd->setMode( QFileDialog::ExistingFile );
fd->setFilter( "Any file (*.*)" );
}
else{ /* select directory */
fd = new QFileDialog( this, "directory open dialog", TRUE );
fd->setMode( QFileDialog::Directory );
}
if ( fd->exec() == QDialog::Accepted ){
fileEdit->setText(fd->selectedFile());
}
}
void PrepareDialog::checkboxChanged(int state)
{
if (sendRButton->isChecked()){ /* select file */
ipEdit->setEnabled(true);
portLabel->setText(tr("Remote port: "));
fileLabel->setText(tr("Select file: "));
}
else{ /* select directory */
ipEdit->setEnabled(false);
portLabel->setText(tr("Local port: "));
fileLabel->setText(tr("Select directory: "));
}
fileEdit->setText("");
}
void PrepareDialog::startReceive(const QString &ip, int port, const QString &folder)
{
FTransferDialog *d = new FTransferDialog(0, NULL, false, Qt::WDestructiveClose ,
ip,port,folder, S_RECEIVE);
d->show();
}
void PrepareDialog::startSend(const QString &ip, int port, const QString &file)
{
FTransferDialog *d = new FTransferDialog(0, NULL, false, Qt::WDestructiveClose,
ip,port,file, S_SEND);
d->show();
}
Соседние файлы в папке net_copy