1 | /****************************************************************************
|
---|
2 | ** $Id: client.cpp 2 2005-11-16 15:49:26Z dmik $
|
---|
3 | **
|
---|
4 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
|
---|
5 | **
|
---|
6 | ** This file is part of an example program for Qt. This example
|
---|
7 | ** program may be used, distributed and modified without limitation.
|
---|
8 | **
|
---|
9 | *****************************************************************************/
|
---|
10 |
|
---|
11 | #include <qapplication.h>
|
---|
12 | #include <qtextedit.h>
|
---|
13 | #include <qpushbutton.h>
|
---|
14 | #include <qfiledialog.h>
|
---|
15 |
|
---|
16 | #include "qip.h"
|
---|
17 | #include "client.h"
|
---|
18 |
|
---|
19 |
|
---|
20 |
|
---|
21 |
|
---|
22 | ClientInfo::ClientInfo( QWidget *parent, const char *name ) :
|
---|
23 | ClientInfoBase( parent, name )
|
---|
24 | {
|
---|
25 | connect( btnOpen, SIGNAL(clicked()), SLOT(downloadFile()) );
|
---|
26 | connect( btnQuit, SIGNAL(clicked()), qApp, SLOT(quit()) );
|
---|
27 | connect( &op, SIGNAL( data( const QByteArray &, QNetworkOperation * ) ),
|
---|
28 | this, SLOT( newData( const QByteArray & ) ) );
|
---|
29 | }
|
---|
30 |
|
---|
31 | void ClientInfo::downloadFile()
|
---|
32 | {
|
---|
33 | // under Windows you must not use the native file dialog
|
---|
34 | QString file = getOpenFileName();
|
---|
35 | if ( !file.isEmpty() ) {
|
---|
36 | infoText->clear();
|
---|
37 | // download the data
|
---|
38 | op = file;
|
---|
39 | op.get();
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | QString ClientInfo::getOpenFileName()
|
---|
44 | {
|
---|
45 | static QString workingDirectory( "qip://localhost/" );
|
---|
46 |
|
---|
47 | QFileDialog dlg( workingDirectory, QString::null, 0, 0, TRUE );
|
---|
48 | dlg.setCaption( QFileDialog::tr( "Open" ) );
|
---|
49 | dlg.setMode( QFileDialog::ExistingFile );
|
---|
50 | QString result;
|
---|
51 | if ( dlg.exec() == QDialog::Accepted ) {
|
---|
52 | result = dlg.selectedFile();
|
---|
53 | workingDirectory = dlg.url();
|
---|
54 | }
|
---|
55 | return result;
|
---|
56 | }
|
---|
57 |
|
---|
58 | void ClientInfo::newData( const QByteArray &ba )
|
---|
59 | {
|
---|
60 | infoText->append( QString::fromUtf8( ba ) );
|
---|
61 | }
|
---|