From bd0f3345a938b35ce6a12f6150373b0955b8dd12 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 10 Jul 2011 15:24:15 -0500 Subject: Add Qt3 development HEAD version --- examples/network/ftpclient/README | 3 + examples/network/ftpclient/connectdialog.ui | 244 ++++++++++++++++++++++ examples/network/ftpclient/ftpclient.doc | 24 +++ examples/network/ftpclient/ftpclient.pro | 14 ++ examples/network/ftpclient/ftpmainwindow.ui | 280 ++++++++++++++++++++++++++ examples/network/ftpclient/ftpmainwindow.ui.h | 273 +++++++++++++++++++++++++ examples/network/ftpclient/ftpviewitem.cpp | 58 ++++++ examples/network/ftpclient/ftpviewitem.h | 35 ++++ examples/network/ftpclient/images/file.png | Bin 0 -> 106 bytes examples/network/ftpclient/images/folder.png | Bin 0 -> 145 bytes examples/network/ftpclient/main.cpp | 23 +++ 11 files changed, 954 insertions(+) create mode 100644 examples/network/ftpclient/README create mode 100644 examples/network/ftpclient/connectdialog.ui create mode 100644 examples/network/ftpclient/ftpclient.doc create mode 100644 examples/network/ftpclient/ftpclient.pro create mode 100644 examples/network/ftpclient/ftpmainwindow.ui create mode 100644 examples/network/ftpclient/ftpmainwindow.ui.h create mode 100644 examples/network/ftpclient/ftpviewitem.cpp create mode 100644 examples/network/ftpclient/ftpviewitem.h create mode 100644 examples/network/ftpclient/images/file.png create mode 100644 examples/network/ftpclient/images/folder.png create mode 100644 examples/network/ftpclient/main.cpp (limited to 'examples/network/ftpclient') diff --git a/examples/network/ftpclient/README b/examples/network/ftpclient/README new file mode 100644 index 0000000..8b1bd7e --- /dev/null +++ b/examples/network/ftpclient/README @@ -0,0 +1,3 @@ +This example is a small ftp client. It shows how to use the QFtp class. + +This example needs the network extension. diff --git a/examples/network/ftpclient/connectdialog.ui b/examples/network/ftpclient/connectdialog.ui new file mode 100644 index 0000000..1531054 --- /dev/null +++ b/examples/network/ftpclient/connectdialog.ui @@ -0,0 +1,244 @@ + +ConnectDialog + + + ConnectDialog + + + + 0 + 0 + 384 + 165 + + + + Choose host to connect to + + + true + + + + unnamed + + + + Frame3 + + + StyledPanel + + + Raised + + + + unnamed + + + + TextLabel2 + + + &Remote Host: + + + host + + + + + TextLabel5 + + + &Username: + + + username + + + + + TextLabel6 + + + &Password: + + + password + + + + + password + + + + + + Password + + + + + username + + + anonymous + + + + + Layout21 + + + + unnamed + + + + host + + + + + TextLabel3 + + + P&ort: + + + port + + + + + port + + + + 1 + 0 + 0 + 0 + + + + 1000 + + + 21 + + + + + + + + + Spacer5 + + + Vertical + + + Expanding + + + + 31 + 0 + + + + + + Layout1 + + + + unnamed + + + 0 + + + 6 + + + + Horizontal Spacing2 + + + Horizontal + + + Expanding + + + + 0 + 20 + + + + + + buttonOk + + + OK + + + 0 + + + true + + + true + + + + + buttonCancel + + + Cancel + + + 0 + + + true + + + + + + + + + buttonOk + clicked() + ConnectDialog + accept() + + + buttonCancel + clicked() + ConnectDialog + reject() + + + + host + port + username + password + buttonOk + buttonCancel + + + diff --git a/examples/network/ftpclient/ftpclient.doc b/examples/network/ftpclient/ftpclient.doc new file mode 100644 index 0000000..13be191 --- /dev/null +++ b/examples/network/ftpclient/ftpclient.doc @@ -0,0 +1,24 @@ +/* +*/ + +/*! \page ftpclient-example.html + + \ingroup network-examples + + \title An FTP client + + This example implements a FTP client. It uses QFtp to perform its FTP + commands. The GUI parts are done in the Designer. + +
+ + The implementation of the FTP commands (ftpmainwindow.ui.h): + + \include network/ftpclient/ftpmainwindow.ui.h + +
+ + Main (main.cpp): + + \include network/ftpclient/main.cpp +*/ diff --git a/examples/network/ftpclient/ftpclient.pro b/examples/network/ftpclient/ftpclient.pro new file mode 100644 index 0000000..eb71f13 --- /dev/null +++ b/examples/network/ftpclient/ftpclient.pro @@ -0,0 +1,14 @@ +TEMPLATE = app +TARGET = ftpclient + +CONFIG += qt warn_on release + +REQUIRES = network full-config nocrosscompiler + +HEADERS = ftpviewitem.h +SOURCES = main.cpp \ + ftpviewitem.cpp +FORMS = ftpmainwindow.ui \ + connectdialog.ui +IMAGES = images/file.png \ + images/folder.png diff --git a/examples/network/ftpclient/ftpmainwindow.ui b/examples/network/ftpclient/ftpmainwindow.ui new file mode 100644 index 0000000..6c3ab30 --- /dev/null +++ b/examples/network/ftpclient/ftpmainwindow.ui @@ -0,0 +1,280 @@ + +FtpMainWindow + + + FtpMainWindow + + + + 0 + 0 + 600 + 480 + + + + Ftp client example + + + + unnamed + + + + + Name + + + true + + + true + + + + + Size + + + true + + + true + + + + + Last Modified + + + true + + + true + + + + remoteView + + + true + + + + + remotePath + + + + 7 + 0 + 0 + 0 + + + + true + + + false + + + + + TextLabel4 + + + &Remote Path: + + + remotePath + + + + + + + menubar + + + + + + + + + + + + + + toolBar + + + Tools + + + + + + + + + + + fileDownloadAction + + + image0 + + + Download... + + + 0 + + + + + fileExitAction + + + Exit + + + E&xit + + + 0 + + + + + fileRemoveAction + + + image1 + + + Remove + + + + + fileUploadAction + + + image2 + + + Upload... + + + + + fileConnectAction + + + image3 + + + Connect... + + + + + + 789c95944953e3301046eff9152e74a3a61ac79bec9a9a03fbbeef4ccdc1926d92400224619d9aff3eeaafc719b640f02387477f96a5b6e49969ef6467d39b9e690c86f9b06d3ddbcafbde7471dbed3efefcf5e377632a083cf797265e30f5ad31b53bf4acb775d52b594839513e2ef86ced710a9faf3d95fa8e7814c621fc066e7c2379056ffa0cea47f066e06b83fa101e30a8afc1331d86325e0c370c7c573cd4b1c5fd863df019d41378c4c0f7e186819f8f1cf7530eaf18789f3df4433f8d313eea61938177e1b8e0182fd40ceedf80e74191c8789138833c8d5ce6b3557b22be5d7b26ebd770cbc0176a97feab01bc60e0d7f08a417ee491f4678e9ddb13a33fcac271a17e0ad78e0ceec35306f9367b1c30a81f8c5ce6b72e9e04f27cd582270cea4db8d6718c7e29ecb73865e05770c3209fc12d030fd993c821e3219f6807fa4b67f08c81a33f3ad56926ebc77c74c9c05378c5c003f634303a95f59dc04387f4a782733be47d3f8d5ccec761edb9e457e0b943d6730caff2dcc8fc57d9315d99ff235c3b24ff00b70e995f092fb332c77ea465f6dc77c8f37af0cc21fd5a849bdc5899ef12dc3a64bc7b78e1102fe0a5431cfbc3440cbc3b729c0fba835b07f61fe13c9a8a81ef8997612a7ec96e7d067e010f18bc7fa9470cead86f78fd721ed17f5b31a8dfb2171103c7f7a4c81c72de3af08a411d5e860c7c13aead95f5a99e380347bf4b6e38f693c27cf1b990f9e27b5165bef6258ffe55b8e4e33a39e3f3a46a26c9534e862c15545245e713e45bd4a60e5dd02575a94757742dcf199bbfa13e0d6848b77447f7f4408ff4c4778ccdcfd21ccdd3022dd2122dd38afbad7e925fa375daa0cd09f35bb44d3bb44b7b13e6f7e9800ee9888e913f71e9d30fd7abe88c7c6a52e03a1a5244f1cb7ebe7d3b9490a69432f72fa572655ee6955585a354953a7ffe14d552ede76ff855bea32ed4a5ea7ebe7ffee57bea4a5dab9bd729d51f937733a28e1a7c21cfd8d7a949f2aa5fa7fea7c7e7395df3c17adf1dffdd3cdf51f366d66ff393f2e5fc9fef8dbfa8437f7d + + + 789ca590c10ac2300c86ef7b8ab2de866c3a0f1ec447503c0ae2214d237a5041e741c477b749376d3bf5e29f16fae7234d4855a8d572ae8a2abb34d0ec51e10eceaab0d7c3e1b6deccee595ed7ca9d891ae5832c2f15aac5e948fcd6eead8722b6c4d68c39d85ab196832db2b5c4c116d81275b586ed56245d3eea3fa25bc504004a6d44a8e31a87003d318c20f8ad43961140d4c733eb5a31080909b28802428224cc5d9d10d79d1100f5894101a64f240fd023922757863169f3c6503cc12befc748f6e6b72363f467f3a274076f2524d47752fe268f69f604fb43a540 + + + 789cd594496fdb301046effe1542780b8a89ac8d128a1eb22fcdbe27450f1425c58e633b5eb216fdefe57c1319718bd6ceb17af1e1851fa5e190d2d2a27779b8e72d2e354663336e5bcfb6ccd05b2c1ebadd976fdfbffc682c0481e7fed2d80b163e35168ec69ef5f6fbbd92859413e5e3822fd71ea7f0d5da53193f148fc238645703f6a6cf60fc1cde0c7c9d637c040f188cefc0331d86984f313c67e047e2a18e2de6e7ec81cf603c81470cfc049e33f0d6c4319f647ec5c087eca11ffa698cfb1b78938177e1b8e03770cd60fe2edc044522f78bc419e469e252cf7eed89f841ed99ac5fc32d035fab5dfaada4de8281dfc32b06f941ed91f467859ddb13a33fcac27161fc0aae1d19dc87a70cf26df63860307e3a71a9efab7812c8f315fa1d270cc69b70ade318fd52385f71cac0fbf09c413e835b061eb2279143ee87f526da81fed2353c63e0385f3ad56926eb47fdba64e029bc62e0017b1ae43a95f55dc24387f407fb8d76c87ebf4e5cde87b3da8de4b7e0c621ebb98057c6e452ff363bca95fa5fe0da21f967b875487d15bccc4a83f3489becc677c8f3d03f9339a45febf0dce456eadd805b87dcef095e38c44b78e9102fd8f38881f7268ef7831ee1d681f347384f79c5c08fc5cb3015c7fb637d067e070f18ecbf78c460fc168e038071acdf560cc61fd88b88818fe19943de37cc2f2a06e31df63264e07b706dadac4ff5c41938fa5172c3719e14e6e37321e703df872af3b52f79f4abc2251fd3f9f97b9e54cdac3c19f7cbc9524125557443ad5979479b6ea94377d4a51ef5e99e06f29ce93c9235431ad1981ee8919ee8995ee89567bccf731d9359cbb442abb446ebb4419bb4e57edbd3f93afd56ff32edd057daa5bdd979d83e1dd0211dd1f19cf9133aa5333aa70be42f5dfaea5ffd777dbf269f9a14b88e8614513cddcf3f778712d29452e6fea59451f9745e5955384a55a99bf74f512dd57ebfc3bfe56f5547dda9eeecf3f396efa9beba5783b9f3ae22eaa8e107f28cfd0ff32337a366343b3f2f1fcefffcdcf80560e77be9 + + + 789c8d95476fe4381085effe150dd7cd58d44854c6600fce394ff0cc620f2425b5533bb4dba1bdd8ff3eac57526381757bac671bf8c0c7122b88feb434383bda1f2c7d5a7898d8c9851ff8733b1e2cd58fa3d1f4afbffffc6761d19841f889e3786016ff58583c9e0cfce0e0f6a611600a40111e611af56c4aacaff45ceafab372e2335ddf574e932c01df835de4749d74bf8b6d5181c7c2e12c69a1fe536513150eeb4fe032c9330f46bcb88aab22833f063b11f84039293aff2ab83565a9f14b611389b07e39630b7e04db2c4d359f23b013818733d6f8ebe0dad4899ec7825b11d65f84932828c6fab8e752fd053816c18ffc1323c27a35639c9f182c4f0a46be499a651def823311f8109c8b106f076c4d9de37c1c298bc0d98c35dfbd9e2b7dff96729176f537602f02aff6acf3c177e0366953ad37e6233522b00327411aef1b38844f311ffc1d5c8ae05f06573649753ed09fd48ac027c2592c02a31f991121def18cf5bcdbcab949b45f0f1d575a0f42fe28a7e6bf0196a700e37bc97211e29d818ba25be71c5c8ac029d88bb01ff5c99acc74f5d5f3b4595beafe9fc2791aa4f16fc145909e0ffdccad088cfcf25604f63d179a3ff22bcaa2acb41f9be02a48eb710e6e44e004dc8ac03f844be38a52e37d052741983f6ec1d22e3dffeb8cb57f6b3d57fabe939eadeec7794a1ba4f3f705dc5aeb903f217e150569bd6ec02648f7633eab3c48e7790a9604755eaec06590f274c67a1e7caf950fd2fa0d7bb63acf0db8a91aabdf33e6c14641fa7e9cc75641dadf1a2c4f8d75e46f9d755eeb83fbc3fa20ad2fee535b0729ebfe264819fd74a9083c9ab17eef389fcb83743ed14f272fd47ae23e753e48cf83efcfb522f0a1729394cad7c23e1281513f6f44e00b30061aef9b8043f619e687743f0a08567f2d02633e7cebdb5aef03cc771d05697cdcc7752a02237e5d05697f717f3789088cfbaf29bcefea83fba20d4f55ea3fbb8f6bbe9fa9d747fc6cd9b1e79a1b6e79f801ff395ff0255ff1358ff8866ff94edf33d77fcf637ee0093ff2133ff30b4ff95576ccf52f07adf02aaff13a6ff066f8dd9aef879b789b7778f7f7fecebdc7fb7cc087bff377ee233ee6133ee52ff07f0dee6f6fe70bbfea3b9ff18f50d19f1c713caf9e5d97c46f38e19433ceb9e0f22d3f57c4c165f44cb2373cf6bf1deefd61c591a79a9ad0a1ce3d7f7e78482d0de99c1d5da89b2ee7fbb90a1578a12b5ea76b44275ea1d1fb7ebaa29bf0f796eee89ec6f4f061ff841ee9899edff3d30b4d3bff2b2dd30aadd21aadbf976fa8cd066d22fe166dd30eedbeed9ed587688ff6c9f1331d840e257d77e6f9b1e3908ed8d0319dccabfdfffb4ba7f39d9dffdfcf0bbf00b514c1b3 + + + + + fileExitAction + activated() + FtpMainWindow + close() + + + fileDownloadAction + activated() + FtpMainWindow + downloadFile() + + + fileRemoveAction + activated() + FtpMainWindow + removeFile() + + + fileUploadAction + activated() + FtpMainWindow + uploadFile() + + + fileConnectAction + activated() + FtpMainWindow + connectToHost() + + + remotePath + activated(const QString&) + FtpMainWindow + changePath(const QString&) + + + remoteView + doubleClicked(QListViewItem*) + FtpMainWindow + changePathOrDownload(QListViewItem*) + + + remoteView + returnPressed(QListViewItem*) + FtpMainWindow + changePathOrDownload(QListViewItem*) + + + + ftpmainwindow.ui.h + + + class QFtp; + class QUrlInfo; + + + QFtp *ftp + QLabel *stateFtp + QString currentFtpDir + + + connectToHost() + uploadFile() + downloadFile() + removeFile() + changePath( const QString & newPath ) + ftp_commandStarted() + ftp_commandFinished() + ftp_done( bool error ) + ftp_stateChanged( int state ) + ftp_listInfo( const QUrlInfo & i ) + ftp_rawCommandReply( int code, const QString & text ) + changePathOrDownload( QListViewItem * ) + + + init() + destroy() + + + diff --git a/examples/network/ftpclient/ftpmainwindow.ui.h b/examples/network/ftpclient/ftpmainwindow.ui.h new file mode 100644 index 0000000..2feeb5a --- /dev/null +++ b/examples/network/ftpclient/ftpmainwindow.ui.h @@ -0,0 +1,273 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +/**************************************************************************** +** +** ui.h extension file, included from the uic-generated form implementation. +** +** The init() function is used in place of a constructor. +** The destroy() function is used in place of a destructor. +** The slots uploadFile(), downloadFile(), removeFile() and connectToHost() are +** connected with the resp. actions of the GUI. +** +*****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "connectdialog.h" +#include "ftpviewitem.h" + +void FtpMainWindow::init() +{ + stateFtp = new QLabel( tr("Unconnected"), statusBar() ); + statusBar()->addWidget( stateFtp, 0, TRUE ); + + ftp = new QFtp( this ); + connect( ftp, SIGNAL(commandStarted(int)), + SLOT(ftp_commandStarted()) ); + connect( ftp, SIGNAL(commandFinished(int,bool)), + SLOT(ftp_commandFinished()) ); + connect( ftp, SIGNAL(done(bool)), + SLOT(ftp_done(bool)) ); + connect( ftp, SIGNAL(stateChanged(int)), + SLOT(ftp_stateChanged(int)) ); + connect( ftp, SIGNAL(listInfo(const QUrlInfo &)), + SLOT(ftp_listInfo(const QUrlInfo &)) ); + connect( ftp, SIGNAL(rawCommandReply(int, const QString &)), + SLOT(ftp_rawCommandReply(int, const QString &)) ); +} + +void FtpMainWindow::destroy() +{ + if ( ftp->state() != QFtp::Unconnected ) + ftp->close(); +} + +void FtpMainWindow::uploadFile() +{ + QString fileName = QFileDialog::getOpenFileName( + QString::null, + QString::null, + this, + "upload file dialog", + tr("Choose a file to upload") ); + if ( fileName.isNull() ) + return; + + QFile *file = new QFile( fileName ); + if ( !file->open( IO_ReadOnly ) ) { + QMessageBox::critical( this, tr("Upload error"), + tr("Can't open file '%1' for reading.").arg(fileName) ); + delete file; + return; + } + + QProgressDialog progress( + tr("Uploading file..."), + tr("Cancel"), + 0, + this, + "upload progress dialog", + TRUE ); + connect( ftp, SIGNAL(dataTransferProgress(int,int)), + &progress, SLOT(setProgress(int,int)) ); + connect( ftp, SIGNAL(commandFinished(int,bool)), + &progress, SLOT(reset()) ); + connect( &progress, SIGNAL(cancelled()), + ftp, SLOT(abort()) ); + + QFileInfo fi( fileName ); + ftp->put( file, fi.fileName() ); + progress.exec(); // ### takes a lot of time!!! + + ftp->list(); +} + +void FtpMainWindow::downloadFile() +{ + FtpViewItem *item = (FtpViewItem*)remoteView->selectedItem(); + if ( !item || item->isDir() ) + return; + + QString fileName = QFileDialog::getSaveFileName( + item->text(0), + QString::null, + this, + "download file dialog", + tr("Save downloaded file as") ); + if ( fileName.isNull() ) + return; + + // create file on the heap because it has to be valid throughout the whole + // asynchronous download operation + QFile *file = new QFile( fileName ); + if ( !file->open( IO_WriteOnly ) ) { + QMessageBox::critical( this, tr("Download error"), + tr("Can't open file '%1' for writing.").arg(fileName) ); + delete file; + return; + } + + QProgressDialog progress( + tr("Downloading file..."), + tr("Cancel"), + 0, + this, + "download progress dialog", + TRUE ); + connect( ftp, SIGNAL(dataTransferProgress(int,int)), + &progress, SLOT(setProgress(int,int)) ); + connect( ftp, SIGNAL(commandFinished(int,bool)), + &progress, SLOT(reset()) ); + connect( &progress, SIGNAL(cancelled()), + ftp, SLOT(abort()) ); + + ftp->get( item->text(0), file ); + progress.exec(); // ### takes a lot of time!!! +} + +void FtpMainWindow::removeFile() +{ + FtpViewItem *item = (FtpViewItem*)remoteView->selectedItem(); + if ( !item || item->isDir() ) + return; + + ftp->remove( item->text(0) ); + ftp->list(); +} + +void FtpMainWindow::connectToHost() +{ + ConnectDialog connectDialog; + if ( connectDialog.exec() == QDialog::Rejected ) + return; + + remotePath->clear(); + remoteView->clear(); + + if ( ftp->state() != QFtp::Unconnected ) + ftp->close(); + + ftp->connectToHost( connectDialog.host->text(), connectDialog.port->value() ); + ftp->login( connectDialog.username->text(), connectDialog.password->text() ); + ftp->rawCommand( "PWD" ); + ftp->list(); +} + +// This slot is connected to the QComboBox::activated() signal of the +// remotePath. +void FtpMainWindow::changePath( const QString &newPath ) +{ + ftp->cd( newPath ); + ftp->rawCommand( "PWD" ); + ftp->list(); +} + +// This slot is connected to the QListView::doubleClicked() and +// QListView::returnPressed() signals of the remoteView. +void FtpMainWindow::changePathOrDownload( QListViewItem *item ) +{ + if ( ((FtpViewItem*)item)->isDir() ) + changePath( item->text(0) ); + else + downloadFile(); +} + +/**************************************************************************** +** +** Slots connected to signals of the QFtp class +** +*****************************************************************************/ + +void FtpMainWindow::ftp_commandStarted() +{ + QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) ); + if ( ftp->currentCommand() == QFtp::List ) { + remoteView->clear(); + if ( currentFtpDir != "/" ) + new FtpViewItem( remoteView, FtpViewItem::Directory, "..", "", "" ); + } +} + +void FtpMainWindow::ftp_commandFinished() +{ + QApplication::restoreOverrideCursor(); + delete ftp->currentDevice(); +} + +void FtpMainWindow::ftp_done( bool error ) +{ + if ( error ) { + QMessageBox::critical( this, tr("FTP Error"), ftp->errorString() ); + + // If we are connected, but not logged in, it is not meaningful to stay + // connected to the server since the error is a really fatal one (login + // failed). + if ( ftp->state() == QFtp::Connected ) + ftp->close(); + } +} + +void FtpMainWindow::ftp_stateChanged( int state ) +{ + switch ( (QFtp::State)state ) { + case QFtp::Unconnected: + stateFtp->setText( tr("Unconnected") ); + break; + case QFtp::HostLookup: + stateFtp->setText( tr("Host lookup") ); + break; + case QFtp::Connecting: + stateFtp->setText( tr("Connecting") ); + break; + case QFtp::Connected: + stateFtp->setText( tr("Connected") ); + break; + case QFtp::LoggedIn: + stateFtp->setText( tr("Logged in") ); + break; + case QFtp::Closing: + stateFtp->setText( tr("Closing") ); + break; + } +} + +void FtpMainWindow::ftp_listInfo( const QUrlInfo &i ) +{ + FtpViewItem::Type type; + if ( i.isDir() ) + type = FtpViewItem::Directory; + else + type = FtpViewItem::File; + + new FtpViewItem( remoteView, type, + i.name(), QString::number(i.size()), i.lastModified().toString() ); +} + +void FtpMainWindow::ftp_rawCommandReply( int code, const QString &text ) +{ + if ( code == 257 ) { + currentFtpDir = text.section( '"', 1, 1 ); + + for ( int i = 0; icount(); i++ ) { + // make sure that we don't insert duplicates + if ( remotePath->text( i ) == currentFtpDir ) + remotePath->removeItem( i ); + } + remotePath->insertItem( currentFtpDir, 0 ); + remotePath->setCurrentItem( 0 ); + } +} diff --git a/examples/network/ftpclient/ftpviewitem.cpp b/examples/network/ftpclient/ftpviewitem.cpp new file mode 100644 index 0000000..bb5d689 --- /dev/null +++ b/examples/network/ftpclient/ftpviewitem.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include + +#include "ftpviewitem.h" + + +FtpViewItem::FtpViewItem( QListView *parent, Type t, const QString &name, const QString &size, const QString &lastModified ) + : QListViewItem(parent,name,size,lastModified), type(t) +{ + // the pixmaps for folders and files are in an image collection + if ( type == Directory ) + setPixmap( 0, QPixmap::fromMimeSource( "folder.png" ) ); + else + setPixmap( 0, QPixmap::fromMimeSource( "file.png" ) ); +} + +int FtpViewItem::compare( QListViewItem * i, int col, bool ascending ) const +{ + // The entry ".." is always the first one. + if ( text(0) == ".." ) { + if ( ascending ) + return -1; + else + return 1; + } + if ( i->text(0) == ".." ) { + if ( ascending ) + return 1; + else + return -1; + } + + // Directories are before files. + if ( type != ((FtpViewItem*)i)->type ) { + if ( type == Directory ) { + if ( ascending ) + return -1; + else + return 1; + } else { + if ( ascending ) + return 1; + else + return -1; + } + } + + // Use default sorting otherwise. + return QListViewItem::compare( i, col, ascending ); +} diff --git a/examples/network/ftpclient/ftpviewitem.h b/examples/network/ftpclient/ftpviewitem.h new file mode 100644 index 0000000..4ea931d --- /dev/null +++ b/examples/network/ftpclient/ftpviewitem.h @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#ifndef FTPVIEWITEM_H +#define FTPVIEWITEM_H + +#include +#include + +class FtpViewItem : public QListViewItem +{ +public: + enum Type { + Directory, + File + }; + + FtpViewItem( QListView *parent, Type t, const QString &name, const QString &size, const QString &lastModified ); + + int compare( QListViewItem * i, int col, bool ascending ) const; + + bool isDir() + { return type==Directory; } + +private: + Type type; +}; + +#endif diff --git a/examples/network/ftpclient/images/file.png b/examples/network/ftpclient/images/file.png new file mode 100644 index 0000000..f042c91 Binary files /dev/null and b/examples/network/ftpclient/images/file.png differ diff --git a/examples/network/ftpclient/images/folder.png b/examples/network/ftpclient/images/folder.png new file mode 100644 index 0000000..5fd0a43 Binary files /dev/null and b/examples/network/ftpclient/images/folder.png differ diff --git a/examples/network/ftpclient/main.cpp b/examples/network/ftpclient/main.cpp new file mode 100644 index 0000000..abd6e89 --- /dev/null +++ b/examples/network/ftpclient/main.cpp @@ -0,0 +1,23 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include +#include "ftpmainwindow.h" + +int main( int argc, char **argv ) +{ + QApplication a( argc, argv ); + + FtpMainWindow m; + a.setMainWidget( &m ); + m.show(); + a.processEvents(); + m.connectToHost(); + return a.exec(); +} -- cgit v1.2.3