📄 dgetmainwin.cpp
字号:
/* * by balancesli * balancesli@gmail.com * * 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 * */#include "dgetMainWin.h"#include "NewUrl.h"#include "tabdialog.h"#include "dget.h"#include <qapplication.h>#include <qvariant.h>#include <qlayout.h>#include <qtooltip.h>#include <qwhatsthis.h>#include <qaction.h>#include <qmenubar.h>#include <qpopupmenu.h>#include <qtoolbar.h>#include <qimage.h>#include <qpixmap.h>#include <qprogressbar.h>#include <qlabel.h>#include <qlineedit.h>#include <qtimer.h>#include <qmessagebox.h>#include <qtabwidget.h>#include <sys/time.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <errno.h>#include <sys/ioctl.h>#include <sys/time.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/param.h>#include <stdint.h>#include <ctype.h>#include <signal.h>#include <unistd.h>#include <assert.h>#include <getopt.h>#include <sys/wait.h>#include "Task.h"#include "FtpCli.h"#include "HttpCli.h"#include "Socket.h"#include "Utils.h"#include "Url.h"#include "dLog.h"#include "dget.h"/********************* dget - download get for linux **********/bool FrmMainWin::IsTargetFileExist(const char * FileName){ struct stat stbuf; if(stat(FileName, &stbuf) == -1) return false; else return true;}uerr_t FrmMainWin::GetFtpRemoteFileInfo(TUrl * u, TFtpCli * fcp){ uerr_t err; err = fcp->Connect(); if (err != FTPOK) { ShowMsgx("Error connecting to %s", u->HostName); return err; } ShowMsgx("Connect Ok"); if(u->UserName == NULL) u->UserName = DEFAULT_FTP_USER; if(u->PassWord == NULL) u->PassWord = DEFAULT_FTP_PASSWD; ShowMsgx("Logging in as user %s password %s", u->UserName, u->PassWord); err = fcp->Login(); if (err != FTPOK) { ShowMsgx("Login Failed"); fcp->Disconnect(); return err; } ShowMsgx("Login OK"); err = fcp->Binary(); if (err != FTPOK) { ShowMsgx("Binary Failed"); fcp->Disconnect(); return err; } ShowMsgx("Type set to binary ok"); if (u->HostDirName) { err = fcp->Cwd(u->HostDirName); if (err != FTPOK) { ShowMsgx("CWD failed to change to directory '%s'", u->HostDirName); fcp->Disconnect(); return err; } ShowMsgx("CWD OK"); } else { ShowMsgx("CWD not needed"); } err = fcp->Rest(0); if (err != FTPOK) { u->ResumeSupport = false; ShowMsgx("REST failed"); } else { u->ResumeSupport = true; ShowMsgx("REST ok"); } err = fcp->Size(u); if (err != FTPOK) { ShowMsgx("Size Command failed"); fcp->Disconnect(); return err; } fcp->Disconnect(); return FTPOK;}/*uerr_t FrmMainWin :: GetHttpRemoteFileInfo(TUrl * u, THttpCli * hcp){}*/int FrmMainWin::GetRemoteFileInfo(TUrl * u){ uerr_t err; if(u->Proto == ptFTP) { TFtpCli * fcp = new TFtpCli(u); err = GetFtpRemoteFileInfo(u, fcp); if (err != FTPOK) { delete fcp; ShowMsgx("Remote File not Exist"); return -1; } delete fcp; return 0; } if(u->Proto == ptHTTP) { HttpStat hs; uerr_t err; THttpCli * hcp = new THttpCli(u); err = hcp->RedirectionParse(u, &hs); if (err != HOK) { delete hcp; ShowMsgx("Remote File not Exist"); return -1; } delete hcp; return 0; }}int FrmMainWin::NewTask( QString url, QString Outdir ){ int nConn = 5; int Retval = 0; char * OutFile = NULL; TTask * Task; char FilePath[1024]; Message * NewMsg; QDateTime dt; if (nConn > 10 || nConn < 0) { ShowMsgx("Max Connections is 10"); return -1; } u = new TUrl(url.latin1 ()); ShowMsgx(url.latin1()); u->ParseUrl(); DispUrl(u); if (u->HostFileName == NULL) { ShowMsgx("File not Exist"); QApplication::restoreOverrideCursor(); return -1; } OutFile = strdup(u->HostFileName); sprintf(FilePath, "%s/%s", Outdir.latin1(), OutFile); if (IsTargetFileExist(FilePath) == true) { ShowMsgx("Target File Exist"); QApplication::restoreOverrideCursor(); return -1; } msg->setText("start connecting ..."); msg->setText(u->HostName); msg->setText("Please Waiting ......"); Retval = GetRemoteFileInfo(u); if( Retval == -1 ) { ShowMsgx("Target File Exist"); QApplication::restoreOverrideCursor(); return Retval ; } DispUrl(u); ShowMsgx("OutputFile :%s", FilePath); QString FileName = u->HostFileName; QString FileSize = QString("%1k").arg(u->FileSize / 1024); dt = QDateTime::currentDateTime(); dt = dt.addSecs( 60 * 6 ); NewMsg = new Message( FileName, FileSize, url, "", "", dt); Task = TaskMgr->CreateTask(nConn); QString folderName = tr("NewTaskBox"); Folder * item = lvs->GetFolderByName(folderName); item->addMessage(NewMsg); lvs->RefreshFolder(item); lvs->InsertTabWidget( NewMsg, Task->GetTaskName() ); QApplication::restoreOverrideCursor(); #ifdef USE_QT// Task->lvs = lvs; Task->msg = NewMsg; Task->messages = lvs->messages; Task->ThreadMsgs = Task->msg->ThreadMsgs; Task->timer = new QTimer( Task ); connect( Task->timer, SIGNAL(timeout()), Task, SLOT( RefreshDisplay() ) ); Task->timer->start( 2500, FALSE );#endif Task->fn = (ThreadFunc)FtpThread; TaskMgr->InitTask( Task, u, FilePath ); TaskMgr->ScheduleTask(Task); msg->setText("downloading ..."); }/* * Constructs a FrmMainWin as a child of 'parent', with the * name 'name' and widget flags set to 'f'. * */FrmMainWin::FrmMainWin( QWidget* parent, const char* name, WFlags fl ) : QMainWindow( parent, name, fl ){ (void)statusBar(); if ( !name ) setName( "FrmMainWin" ); // actions fileNewUrlAction = new QAction( this, "fileNewUrlAction" ); QPixmap icon0(INSTALLDIR"images/openlog.png"); fileNewUrlAction->setIconSet( QIconSet(icon0) ); filePrefAction = new QAction( this, "filePrefAction" ); QPixmap icon1(INSTALLDIR"images/preferences.png"); filePrefAction->setIconSet( QIconSet(icon1) ); fileExitAction = new QAction( this, "fileExitAction" ); QPixmap icon2(INSTALLDIR"images/add.png"); fileExitAction->setIconSet( QIconSet(icon2) ); editStartAction = new QAction( this, "editStartAction" ); QPixmap icon3(INSTALLDIR"images/run.png"); editStartAction->setIconSet( QIconSet(icon3) ); editStopAction = new QAction( this, "editStopAction" ); QPixmap icon4(INSTALLDIR"images/stop.png"); editStopAction->setIconSet( QIconSet(icon4) ); editRestartAction = new QAction( this, "editRestartAction" ); QPixmap icon5(INSTALLDIR"images/runbad.png"); editRestartAction->setIconSet( QIconSet(icon5) ); editResumeAction = new QAction( this, "editResumeAction" ); QPixmap icon6(INSTALLDIR"images/runpart.png"); editResumeAction->setIconSet( QIconSet(icon6) ); editRemoveAction = new QAction( this, "editRemoveAction" ); QPixmap icon7(INSTALLDIR"images/del.png"); editRemoveAction->setIconSet( QIconSet(icon7) ); helpContentsAction = new QAction( this, "helpContentsAction" ); helpIndexAction = new QAction( this, "helpIndexAction" ); helpAboutAction = new QAction( this, "helpAboutAction" ); Toolbar = new QToolBar( QString(""), this, DockTop ); fileNewUrlAction->addTo( Toolbar ); filePrefAction->addTo( Toolbar ); Toolbar->addSeparator();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -