~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to .pc/debian-changes-4:4.7.1-0ubuntu7/doc/html/network-torrent-mainwindow-cpp.html

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2011-01-18 20:37:32 UTC
  • Revision ID: james.westby@ubuntu.com-20110118203732-butn2uvaa6hydoqu
Tags: 4:4.7.1-0ubuntu8
Add kubuntu_26_dbusconnection_pointer.diff,
kubuntu_27_dbus_signal_filter_passes_not_handled.diff from Qt 4.8
to add a way to obtain the DBusConnectionpointer from a
QDBusConnection.  Requested by Ryan Lortie

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?xml version="1.0" encoding="UTF-8"?>
2
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
4
 
<head>
5
 
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
 
  <title>Qt 4.7: mainwindow.cpp Example File (network/torrent/mainwindow.cpp)</title>
7
 
  <link rel="stylesheet" type="text/css" href="style/style.css" />
8
 
  <script src="scripts/jquery.js" type="text/javascript"></script>
9
 
  <script src="scripts/functions.js" type="text/javascript"></script>
10
 
</head>
11
 
<body class="offline narrow creator">
12
 
 <div class="header" id="qtdocheader">
13
 
    <div class="content"> 
14
 
    <div id="nav-logo">
15
 
      <a href="index.html">Home</a></div>
16
 
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
17
 
    <div id="nav-topright">
18
 
      <ul>
19
 
        <li class="nav-topright-home"><a href="http://qt.nokia.com/">Qt HOME</a></li>
20
 
        <li class="nav-topright-dev"><a href="http://developer.qt.nokia.com/">DEV</a></li>
21
 
        <li class="nav-topright-labs"><a href="http://labs.qt.nokia.com/blogs/">LABS</a></li>
22
 
        <li class="nav-topright-doc nav-topright-doc-active"><a href="http://doc.qt.nokia.com/">
23
 
          DOC</a></li>
24
 
        <li class="nav-topright-blog"><a href="http://blog.qt.nokia.com/">BLOG</a></li>
25
 
      </ul>
26
 
    </div>
27
 
    <div id="shortCut">
28
 
      <ul>
29
 
        <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.7</a></span></li>
30
 
        <li class="shortCut-topleft-active"><a href="http://doc.qt.nokia.com">ALL VERSIONS        </a></li>
31
 
      </ul>
32
 
     </div>
33
 
 <ul class="sf-menu sf-js-enabled sf-shadow" id="narrowmenu"> 
34
 
                 <li><a href="#">API Lookup</a> 
35
 
                         <ul id="topmenuLook"> 
36
 
                           <li><a href="classes.html">Class index</a></li> 
37
 
                          <li><a href="functions.html">Function index</a></li> 
38
 
                           <li><a href="modules.html">Modules</a></li> 
39
 
                           <li><a href="namespaces.html">Namespaces</a></li> 
40
 
                           <li><a href="qtglobal.html">Global Declarations</a></li> 
41
 
                           <li><a href="licensing.html">Licenses and Credits</a></li> 
42
 
                           </ul> 
43
 
                 </li> 
44
 
                 <li><a href="#">Qt Topics</a> 
45
 
                         <ul id="topmenuTopic"> 
46
 
                           <li><a href="qt-basic-concepts.html">Programming with Qt</a></li> 
47
 
                           <li><a href="qtquick.html">Device UI's &amp; Qt Quick</a></li> 
48
 
                           <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li> 
49
 
                           <li><a href="developing-with-qt.html">Cross-platform and Platform-specific</a></li> 
50
 
                           <li><a href="platform-specific.html">Platform-specific info</a></li> 
51
 
                           <li><a href="technology-apis.html">Qt and Key Technologies</a></li> 
52
 
                           <li><a href="best-practices.html">How-To's and Best Practices</a></li> 
53
 
                         </ul> 
54
 
                </li> 
55
 
                 <li><a href="#">Examples</a> 
56
 
                         <ul id="topmenuexample"> 
57
 
                                 <li><a href="all-examples.html">Examples</a></li> 
58
 
                                 <li><a href="tutorials.html">Tutorials</a></li> 
59
 
                                 <li><a href="demos.html">Demos</a></li> 
60
 
                                 <li><a href="qdeclarativeexamples.html">QML Examples</a></li> 
61
 
                         </ul> 
62
 
                 </li> 
63
 
 </ul> 
64
 
    </div>
65
 
  </div>
66
 
  <div class="wrapper">
67
 
    <div class="hd">
68
 
      <span></span>
69
 
    </div>
70
 
    <div class="bd group">
71
 
      <div class="sidebar">
72
 
        <div class="searchlabel">
73
 
          Search index:</div>
74
 
        <div class="search">
75
 
          <form id="qtdocsearch" action="" onsubmit="return false;">
76
 
            <fieldset>
77
 
              <input type="text" name="searchstring" id="pageType" value="" />
78
 
            </fieldset>
79
 
          </form>
80
 
        </div>
81
 
        <div class="box first bottombar" id="lookup">
82
 
          <h2 title="API Lookup"><span></span>
83
 
            API Lookup</h2>
84
 
          <div  id="list001" class="list">
85
 
          <ul id="ul001" >
86
 
              <li class="defaultLink"><a href="classes.html">Class index</a></li>
87
 
              <li class="defaultLink"><a href="functions.html">Function index</a></li>
88
 
              <li class="defaultLink"><a href="modules.html">Modules</a></li>
89
 
              <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li>
90
 
              <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li>
91
 
              <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li>
92
 
            </ul> 
93
 
          </div>
94
 
        </div>
95
 
        <div class="box bottombar" id="topics">
96
 
          <h2 title="Qt Topics"><span></span>
97
 
            Qt Topics</h2>
98
 
          <div id="list002" class="list">
99
 
            <ul id="ul002" >
100
 
                           <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li> 
101
 
                           <li class="defaultLink"><a href="qtquick.html">Device UI's &amp; Qt Quick</a></li> 
102
 
                           <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li> 
103
 
                           <li class="defaultLink"><a href="developing-with-qt.html">Cross-platform and Platform-specific</a></li> 
104
 
                           <li class="defaultLink"><a href="platform-specific.html">Platform-specific info</a></li> 
105
 
                           <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li> 
106
 
                           <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li> 
107
 
            </ul>  
108
 
          </div>
109
 
        </div>
110
 
        <div class="box" id="examples">
111
 
          <h2 title="Examples"><span></span>
112
 
            Examples</h2>
113
 
          <div id="list003" class="list">
114
 
        <ul id="ul003">
115
 
              <li class="defaultLink"><a href="all-examples.html">Examples</a></li>
116
 
              <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li>
117
 
              <li class="defaultLink"><a href="demos.html">Demos</a></li>
118
 
              <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li>
119
 
            </ul> 
120
 
          </div>
121
 
        </div>
122
 
      </div>
123
 
      <div class="wrap">
124
 
        <div class="toolbar">
125
 
          <div class="breadcrumb toolblock">
126
 
            <ul>
127
 
              <li class="first"><a href="index.html">Home</a></li>
128
 
              <!--  Bread crumbs goes here -->
129
 
            </ul>
130
 
          </div>
131
 
          <div class="toolbuttons toolblock">
132
 
            <ul>
133
 
              <li id="smallA" class="t_button">A</li>
134
 
              <li id="medA" class="t_button active">A</li>
135
 
              <li id="bigA" class="t_button">A</li>
136
 
              <li id="print" class="t_button"><a href="javascript:this.print();">
137
 
                <span>Print</span></a></li>
138
 
            </ul>
139
 
        </div>
140
 
        </div>
141
 
        <div class="content">
142
 
<h1 class="title">mainwindow.cpp Example File</h1>
143
 
<span class="small-subtitle">network/torrent/mainwindow.cpp</span>
144
 
<!-- $$$network/torrent/mainwindow.cpp-description -->
145
 
<div class="descr"> <a name="details"></a>
146
 
<pre class="highlightedCode brush: cpp"><span class="comment"> /****************************************************************************
147
 
 **
148
 
 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
149
 
 ** All rights reserved.
150
 
 ** Contact: Nokia Corporation (qt-info@nokia.com)
151
 
 **
152
 
 ** This file is part of the examples of the Qt Toolkit.
153
 
 **
154
 
 ** $QT_BEGIN_LICENSE:BSD$
155
 
 ** You may use this file under the terms of the BSD license as follows:
156
 
 **
157
 
 ** &quot;Redistribution and use in source and binary forms, with or without
158
 
 ** modification, are permitted provided that the following conditions are
159
 
 ** met:
160
 
 **   * Redistributions of source code must retain the above copyright
161
 
 **     notice, this list of conditions and the following disclaimer.
162
 
 **   * Redistributions in binary form must reproduce the above copyright
163
 
 **     notice, this list of conditions and the following disclaimer in
164
 
 **     the documentation and/or other materials provided with the
165
 
 **     distribution.
166
 
 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
167
 
 **     the names of its contributors may be used to endorse or promote
168
 
 **     products derived from this software without specific prior written
169
 
 **     permission.
170
 
 **
171
 
 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172
 
 ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
173
 
 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
174
 
 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
175
 
 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
176
 
 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
177
 
 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
178
 
 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
179
 
 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
180
 
 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
181
 
 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
182
 
 ** $QT_END_LICENSE$
183
 
 **
184
 
 ****************************************************************************/</span>
185
 
 
186
 
 #include &lt;QtGui&gt;
187
 
 
188
 
 #include &quot;addtorrentdialog.h&quot;
189
 
 #include &quot;mainwindow.h&quot;
190
 
 #include &quot;ratecontroller.h&quot;
191
 
 #include &quot;torrentclient.h&quot;
192
 
 
193
 
<span class="comment"> // TorrentView extends QTreeWidget to allow drag and drop.</span>
194
 
 class TorrentView : public QTreeWidget
195
 
 {
196
 
     Q_OBJECT
197
 
 public:
198
 
     TorrentView(QWidget *parent = 0);
199
 
 
200
 
 signals:
201
 
     void fileDropped(const QString &amp;fileName);
202
 
 
203
 
 protected:
204
 
     void dragMoveEvent(QDragMoveEvent *event);
205
 
     void dropEvent(QDropEvent *event);
206
 
 };
207
 
 
208
 
<span class="comment"> // TorrentViewDelegate is used to draw the progress bars.</span>
209
 
 class TorrentViewDelegate : public QItemDelegate
210
 
 {
211
 
     Q_OBJECT
212
 
 public:
213
 
     inline TorrentViewDelegate(MainWindow *mainWindow) : QItemDelegate(mainWindow) {}
214
 
 
215
 
     inline void paint(QPainter *painter, const QStyleOptionViewItem &amp;option,
216
 
                       const QModelIndex &amp;index ) const
217
 
     {
218
 
         if (index.column() != 2) {
219
 
             QItemDelegate::paint(painter, option, index);
220
 
             return;
221
 
         }
222
 
 
223
 
         <span class="comment">// Set up a QStyleOptionProgressBar to precisely mimic the</span>
224
 
         <span class="comment">// environment of a progress bar.</span>
225
 
         QStyleOptionProgressBar progressBarOption;
226
 
         progressBarOption.state = QStyle::State_Enabled;
227
 
         progressBarOption.direction = QApplication::layoutDirection();
228
 
         progressBarOption.rect = option.rect;
229
 
         progressBarOption.fontMetrics = QApplication::fontMetrics();
230
 
         progressBarOption.minimum = 0;
231
 
         progressBarOption.maximum = 100;
232
 
         progressBarOption.textAlignment = Qt::AlignCenter;
233
 
         progressBarOption.textVisible = true;
234
 
 
235
 
         <span class="comment">// Set the progress and text values of the style option.</span>
236
 
         int progress = qobject_cast&lt;MainWindow *&gt;(parent())-&gt;clientForRow(index.row())-&gt;progress();
237
 
         progressBarOption.progress = progress &lt; 0 ? 0 : progress;
238
 
         progressBarOption.text = QString().sprintf(&quot;%d%%&quot;, progressBarOption.progress);
239
 
 
240
 
         <span class="comment">// Draw the progress bar onto the view.</span>
241
 
         QApplication::style()-&gt;drawControl(QStyle::CE_ProgressBar, &amp;progressBarOption, painter);
242
 
     }
243
 
 };
244
 
 
245
 
 MainWindow::MainWindow(QWidget *parent)
246
 
     : QMainWindow(parent), quitDialog(0), saveChanges(false)
247
 
 {
248
 
     <span class="comment">// Initialize some static strings</span>
249
 
     QStringList headers;
250
 
     headers &lt;&lt; tr(&quot;Torrent&quot;) &lt;&lt; tr(&quot;Peers/Seeds&quot;) &lt;&lt; tr(&quot;Progress&quot;)
251
 
             &lt;&lt; tr(&quot;Down rate&quot;) &lt;&lt; tr(&quot;Up rate&quot;) &lt;&lt; tr(&quot;Status&quot;);
252
 
 
253
 
     <span class="comment">// Main torrent list</span>
254
 
     torrentView = new TorrentView(this);
255
 
     torrentView-&gt;setItemDelegate(new TorrentViewDelegate(this));
256
 
     torrentView-&gt;setHeaderLabels(headers);
257
 
     torrentView-&gt;setSelectionBehavior(QAbstractItemView::SelectRows);
258
 
     torrentView-&gt;setAlternatingRowColors(true);
259
 
     torrentView-&gt;setRootIsDecorated(false);
260
 
     setCentralWidget(torrentView);
261
 
 
262
 
     <span class="comment">// Set header resize modes and initial section sizes</span>
263
 
     QFontMetrics fm = fontMetrics();
264
 
     QHeaderView *header = torrentView-&gt;header();
265
 
     header-&gt;resizeSection(0, fm.width(&quot;typical-name-for-a-torrent.torrent&quot;));
266
 
     header-&gt;resizeSection(1, fm.width(headers.at(1) + &quot;  &quot;));
267
 
     header-&gt;resizeSection(2, fm.width(headers.at(2) + &quot;  &quot;));
268
 
     header-&gt;resizeSection(3, qMax(fm.width(headers.at(3) + &quot;  &quot;), fm.width(&quot; 1234.0 KB/s &quot;)));
269
 
     header-&gt;resizeSection(4, qMax(fm.width(headers.at(4) + &quot;  &quot;), fm.width(&quot; 1234.0 KB/s &quot;)));
270
 
     header-&gt;resizeSection(5, qMax(fm.width(headers.at(5) + &quot;  &quot;), fm.width(tr(&quot;Downloading&quot;) + &quot;  &quot;)));
271
 
 
272
 
     <span class="comment">// Create common actions</span>
273
 
     QAction *newTorrentAction = new QAction(QIcon(&quot;:/icons/bottom.png&quot;), tr(&quot;Add &amp;new torrent&quot;), this);
274
 
     pauseTorrentAction = new QAction(QIcon(&quot;:/icons/player_pause.png&quot;), tr(&quot;&amp;Pause torrent&quot;), this);
275
 
     removeTorrentAction = new QAction(QIcon(&quot;:/icons/player_stop.png&quot;), tr(&quot;&amp;Remove torrent&quot;), this);
276
 
 
277
 
     <span class="comment">// File menu</span>
278
 
     QMenu *fileMenu = menuBar()-&gt;addMenu(tr(&quot;&amp;File&quot;));
279
 
     fileMenu-&gt;addAction(newTorrentAction);
280
 
     fileMenu-&gt;addAction(pauseTorrentAction);
281
 
     fileMenu-&gt;addAction(removeTorrentAction);
282
 
     fileMenu-&gt;addSeparator();
283
 
     fileMenu-&gt;addAction(QIcon(&quot;:/icons/exit.png&quot;), tr(&quot;E&amp;xit&quot;), this, SLOT(close()));
284
 
 
285
 
     <span class="comment">// Help menu</span>
286
 
     QMenu *helpMenu = menuBar()-&gt;addMenu(tr(&quot;&amp;Help&quot;));
287
 
     helpMenu-&gt;addAction(tr(&quot;&amp;About&quot;), this, SLOT(about()));
288
 
     helpMenu-&gt;addAction(tr(&quot;About &amp;Qt&quot;), qApp, SLOT(aboutQt()));
289
 
 
290
 
     <span class="comment">// Top toolbar</span>
291
 
     QToolBar *topBar = new QToolBar(tr(&quot;Tools&quot;));
292
 
     addToolBar(Qt::TopToolBarArea, topBar);
293
 
     topBar-&gt;setMovable(false);
294
 
     topBar-&gt;addAction(newTorrentAction);
295
 
     topBar-&gt;addAction(removeTorrentAction);
296
 
     topBar-&gt;addAction(pauseTorrentAction);
297
 
     topBar-&gt;addSeparator();
298
 
     downActionTool = topBar-&gt;addAction(QIcon(tr(&quot;:/icons/1downarrow.png&quot;)), tr(&quot;Move down&quot;));
299
 
     upActionTool = topBar-&gt;addAction(QIcon(tr(&quot;:/icons/1uparrow.png&quot;)), tr(&quot;Move up&quot;));
300
 
 
301
 
     <span class="comment">// Bottom toolbar</span>
302
 
     QToolBar *bottomBar = new QToolBar(tr(&quot;Rate control&quot;));
303
 
     addToolBar(Qt::BottomToolBarArea, bottomBar);
304
 
     bottomBar-&gt;setMovable(false);
305
 
     downloadLimitSlider = new QSlider(Qt::Horizontal);
306
 
     downloadLimitSlider-&gt;setRange(0, 1000);
307
 
     bottomBar-&gt;addWidget(new QLabel(tr(&quot;Max download:&quot;)));
308
 
     bottomBar-&gt;addWidget(downloadLimitSlider);
309
 
     bottomBar-&gt;addWidget((downloadLimitLabel = new QLabel(tr(&quot;0 KB/s&quot;))));
310
 
     downloadLimitLabel-&gt;setFixedSize(QSize(fm.width(tr(&quot;99999 KB/s&quot;)), fm.lineSpacing()));
311
 
     bottomBar-&gt;addSeparator();
312
 
     uploadLimitSlider = new QSlider(Qt::Horizontal);
313
 
     uploadLimitSlider-&gt;setRange(0, 1000);
314
 
     bottomBar-&gt;addWidget(new QLabel(tr(&quot;Max upload:&quot;)));
315
 
     bottomBar-&gt;addWidget(uploadLimitSlider);
316
 
     bottomBar-&gt;addWidget((uploadLimitLabel = new QLabel(tr(&quot;0 KB/s&quot;))));
317
 
     uploadLimitLabel-&gt;setFixedSize(QSize(fm.width(tr(&quot;99999 KB/s&quot;)), fm.lineSpacing()));
318
 
 
319
 
     <span class="comment">// Set up connections</span>
320
 
     connect(torrentView, SIGNAL(itemSelectionChanged()),
321
 
             this, SLOT(setActionsEnabled()));
322
 
     connect(torrentView, SIGNAL(fileDropped(QString)),
323
 
             this, SLOT(acceptFileDrop(QString)));
324
 
     connect(uploadLimitSlider, SIGNAL(valueChanged(int)),
325
 
             this, SLOT(setUploadLimit(int)));
326
 
     connect(downloadLimitSlider, SIGNAL(valueChanged(int)),
327
 
             this, SLOT(setDownloadLimit(int)));
328
 
     connect(newTorrentAction, SIGNAL(triggered()),
329
 
             this, SLOT(addTorrent()));
330
 
     connect(pauseTorrentAction, SIGNAL(triggered()),
331
 
             this, SLOT(pauseTorrent()));
332
 
     connect(removeTorrentAction, SIGNAL(triggered()),
333
 
             this, SLOT(removeTorrent()));
334
 
     connect(upActionTool, SIGNAL(triggered(bool)),
335
 
             this, SLOT(moveTorrentUp()));
336
 
     connect(downActionTool, SIGNAL(triggered(bool)),
337
 
             this, SLOT(moveTorrentDown()));
338
 
 
339
 
     <span class="comment">// Load settings and start</span>
340
 
     setWindowTitle(tr(&quot;Torrent Client&quot;));
341
 
     setActionsEnabled();
342
 
     QMetaObject::invokeMethod(this, &quot;loadSettings&quot;, Qt::QueuedConnection);
343
 
 }
344
 
 
345
 
 QSize MainWindow::sizeHint() const
346
 
 {
347
 
     const QHeaderView *header = torrentView-&gt;header();
348
 
 
349
 
     <span class="comment">// Add up the sizes of all header sections. The last section is</span>
350
 
     <span class="comment">// stretched, so its size is relative to the size of the width;</span>
351
 
     <span class="comment">// instead of counting it, we count the size of its largest value.</span>
352
 
     int width = fontMetrics().width(tr(&quot;Downloading&quot;) + &quot;  &quot;);
353
 
     for (int i = 0; i &lt; header-&gt;count() - 1; ++i)
354
 
         width += header-&gt;sectionSize(i);
355
 
 
356
 
     return QSize(width, QMainWindow::sizeHint().height())
357
 
         .expandedTo(QApplication::globalStrut());
358
 
 }
359
 
 
360
 
 const TorrentClient *MainWindow::clientForRow(int row) const
361
 
 {
362
 
     <span class="comment">// Return the client at the given row.</span>
363
 
     return jobs.at(row).client;
364
 
 }
365
 
 
366
 
 int MainWindow::rowOfClient(TorrentClient *client) const
367
 
 {
368
 
     <span class="comment">// Return the row that displays this client's status, or -1 if the</span>
369
 
     <span class="comment">// client is not known.</span>
370
 
     int row = 0;
371
 
     foreach (Job job, jobs) {
372
 
         if (job.client == client)
373
 
             return row;
374
 
         ++row;
375
 
     }
376
 
     return -1;
377
 
 }
378
 
 
379
 
 void MainWindow::loadSettings()
380
 
 {
381
 
     <span class="comment">// Load base settings (last working directory, upload/download limits).</span>
382
 
     QSettings settings(&quot;Trolltech&quot;, &quot;Torrent&quot;);
383
 
     lastDirectory = settings.value(&quot;LastDirectory&quot;).toString();
384
 
     if (lastDirectory.isEmpty())
385
 
         lastDirectory = QDir::currentPath();
386
 
     int up = settings.value(&quot;UploadLimit&quot;).toInt();
387
 
     int down = settings.value(&quot;DownloadLimit&quot;).toInt();
388
 
     uploadLimitSlider-&gt;setValue(up ? up : 170);
389
 
     downloadLimitSlider-&gt;setValue(down ? down : 550);
390
 
 
391
 
     <span class="comment">// Resume all previous downloads.</span>
392
 
     int size = settings.beginReadArray(&quot;Torrents&quot;);
393
 
     for (int i = 0; i &lt; size; ++i) {
394
 
         settings.setArrayIndex(i);
395
 
         QByteArray resumeState = settings.value(&quot;resumeState&quot;).toByteArray();
396
 
         QString fileName = settings.value(&quot;sourceFileName&quot;).toString();
397
 
         QString dest = settings.value(&quot;destinationFolder&quot;).toString();
398
 
 
399
 
         if (addTorrent(fileName, dest, resumeState)) {
400
 
             TorrentClient *client = jobs.last().client;
401
 
             client-&gt;setDownloadedBytes(settings.value(&quot;downloadedBytes&quot;).toLongLong());
402
 
             client-&gt;setUploadedBytes(settings.value(&quot;uploadedBytes&quot;).toLongLong());
403
 
         }
404
 
     }
405
 
 }
406
 
 
407
 
 bool MainWindow::addTorrent()
408
 
 {
409
 
     <span class="comment">// Show the file dialog, let the user select what torrent to start downloading.</span>
410
 
     QString fileName = QFileDialog::getOpenFileName(this, tr(&quot;Choose a torrent file&quot;),
411
 
                                                     lastDirectory,
412
 
                                                     tr(&quot;Torrents (*.torrent);;&quot;
413
 
                                                        &quot; All files (*.*)&quot;));
414
 
     if (fileName.isEmpty())
415
 
         return false;
416
 
     lastDirectory = QFileInfo(fileName).absolutePath();
417
 
 
418
 
     <span class="comment">// Show the &quot;Add Torrent&quot; dialog.</span>
419
 
     AddTorrentDialog *addTorrentDialog = new AddTorrentDialog(this);
420
 
     addTorrentDialog-&gt;setTorrent(fileName);
421
 
     addTorrentDialog-&gt;deleteLater();
422
 
     if (!addTorrentDialog-&gt;exec())
423
 
         return false;
424
 
 
425
 
     <span class="comment">// Add the torrent to our list of downloads</span>
426
 
     addTorrent(fileName, addTorrentDialog-&gt;destinationFolder());
427
 
     if (!saveChanges) {
428
 
         saveChanges = true;
429
 
         QTimer::singleShot(1000, this, SLOT(saveSettings()));
430
 
     }
431
 
     return true;
432
 
 }
433
 
 
434
 
 void MainWindow::removeTorrent()
435
 
 {
436
 
     <span class="comment">// Find the row of the current item, and find the torrent client</span>
437
 
     <span class="comment">// for that row.</span>
438
 
     int row = torrentView-&gt;indexOfTopLevelItem(torrentView-&gt;currentItem());
439
 
     TorrentClient *client = jobs.at(row).client;
440
 
 
441
 
     <span class="comment">// Stop the client.</span>
442
 
     client-&gt;disconnect();
443
 
     connect(client, SIGNAL(stopped()), this, SLOT(torrentStopped()));
444
 
     client-&gt;stop();
445
 
 
446
 
     <span class="comment">// Remove the row from the view.</span>
447
 
     delete torrentView-&gt;takeTopLevelItem(row);
448
 
     jobs.removeAt(row);
449
 
     setActionsEnabled();
450
 
 
451
 
     saveChanges = true;
452
 
     saveSettings();
453
 
 }
454
 
 
455
 
 void MainWindow::torrentStopped()
456
 
 {
457
 
     <span class="comment">// Schedule the client for deletion.</span>
458
 
     TorrentClient *client = qobject_cast&lt;TorrentClient *&gt;(sender());
459
 
     client-&gt;deleteLater();
460
 
 
461
 
     <span class="comment">// If the quit dialog is shown, update its progress.</span>
462
 
     if (quitDialog) {
463
 
         if (++jobsStopped == jobsToStop)
464
 
             quitDialog-&gt;close();
465
 
     }
466
 
 }
467
 
 
468
 
 void MainWindow::torrentError(TorrentClient::Error)
469
 
 {
470
 
     <span class="comment">// Delete the client.</span>
471
 
     TorrentClient *client = qobject_cast&lt;TorrentClient *&gt;(sender());
472
 
     int row = rowOfClient(client);
473
 
     QString fileName = jobs.at(row).torrentFileName;
474
 
     jobs.removeAt(row);
475
 
 
476
 
     <span class="comment">// Display the warning.</span>
477
 
     QMessageBox::warning(this, tr(&quot;Error&quot;),
478
 
                          tr(&quot;An error occurred while downloading %0: %1&quot;)
479
 
                          .arg(fileName)
480
 
                          .arg(client-&gt;errorString()));
481
 
 
482
 
     delete torrentView-&gt;takeTopLevelItem(row);
483
 
     client-&gt;deleteLater();
484
 
 }
485
 
 
486
 
 bool MainWindow::addTorrent(const QString &amp;fileName, const QString &amp;destinationFolder,
487
 
                             const QByteArray &amp;resumeState)
488
 
 {
489
 
     <span class="comment">// Check if the torrent is already being downloaded.</span>
490
 
     foreach (Job job, jobs) {
491
 
         if (job.torrentFileName == fileName &amp;&amp; job.destinationDirectory == destinationFolder) {
492
 
             QMessageBox::warning(this, tr(&quot;Already downloading&quot;),
493
 
                                  tr(&quot;The torrent file %1 is &quot;
494
 
                                     &quot;already being downloaded.&quot;).arg(fileName));
495
 
             return false;
496
 
         }
497
 
     }
498
 
 
499
 
     <span class="comment">// Create a new torrent client and attempt to parse the torrent data.</span>
500
 
     TorrentClient *client = new TorrentClient(this);
501
 
     if (!client-&gt;setTorrent(fileName)) {
502
 
         QMessageBox::warning(this, tr(&quot;Error&quot;),
503
 
                              tr(&quot;The torrent file %1 cannot not be opened/resumed.&quot;).arg(fileName));
504
 
         delete client;
505
 
         return false;
506
 
     }
507
 
     client-&gt;setDestinationFolder(destinationFolder);
508
 
     client-&gt;setDumpedState(resumeState);
509
 
 
510
 
     <span class="comment">// Setup the client connections.</span>
511
 
     connect(client, SIGNAL(stateChanged(TorrentClient::State)), this, SLOT(updateState(TorrentClient::State)));
512
 
     connect(client, SIGNAL(peerInfoUpdated()), this, SLOT(updatePeerInfo()));
513
 
     connect(client, SIGNAL(progressUpdated(int)), this, SLOT(updateProgress(int)));
514
 
     connect(client, SIGNAL(downloadRateUpdated(int)), this, SLOT(updateDownloadRate(int)));
515
 
     connect(client, SIGNAL(uploadRateUpdated(int)), this, SLOT(updateUploadRate(int)));
516
 
     connect(client, SIGNAL(stopped()), this, SLOT(torrentStopped()));
517
 
     connect(client, SIGNAL(error(TorrentClient::Error)), this, SLOT(torrentError(TorrentClient::Error)));
518
 
 
519
 
     <span class="comment">// Add the client to the list of downloading jobs.</span>
520
 
     Job job;
521
 
     job.client = client;
522
 
     job.torrentFileName = fileName;
523
 
     job.destinationDirectory = destinationFolder;
524
 
     jobs &lt;&lt; job;
525
 
 
526
 
     <span class="comment">// Create and add a row in the torrent view for this download.</span>
527
 
     QTreeWidgetItem *item = new QTreeWidgetItem(torrentView);
528
 
 
529
 
     QString baseFileName = QFileInfo(fileName).fileName();
530
 
     if (baseFileName.toLower().endsWith(&quot;.torrent&quot;))
531
 
         baseFileName.remove(baseFileName.size() - 8);
532
 
 
533
 
     item-&gt;setText(0, baseFileName);
534
 
     item-&gt;setToolTip(0, tr(&quot;Torrent: %1&lt;br&gt;Destination: %2&quot;)
535
 
                      .arg(baseFileName).arg(destinationFolder));
536
 
     item-&gt;setText(1, tr(&quot;0/0&quot;));
537
 
     item-&gt;setText(2, &quot;0&quot;);
538
 
     item-&gt;setText(3, &quot;0.0 KB/s&quot;);
539
 
     item-&gt;setText(4, &quot;0.0 KB/s&quot;);
540
 
     item-&gt;setText(5, tr(&quot;Idle&quot;));
541
 
     item-&gt;setFlags(item-&gt;flags() &amp; ~Qt::ItemIsEditable);
542
 
     item-&gt;setTextAlignment(1, Qt::AlignHCenter);
543
 
 
544
 
     if (!saveChanges) {
545
 
         saveChanges = true;
546
 
         QTimer::singleShot(5000, this, SLOT(saveSettings()));
547
 
     }
548
 
     client-&gt;start();
549
 
     return true;
550
 
 }
551
 
 
552
 
 void MainWindow::saveSettings()
553
 
 {
554
 
     if (!saveChanges)
555
 
       return;
556
 
     saveChanges = false;
557
 
 
558
 
     <span class="comment">// Prepare and reset the settings</span>
559
 
     QSettings settings(&quot;Trolltech&quot;, &quot;Torrent&quot;);
560
 
     settings.clear();
561
 
 
562
 
     settings.setValue(&quot;LastDirectory&quot;, lastDirectory);
563
 
     settings.setValue(&quot;UploadLimit&quot;, uploadLimitSlider-&gt;value());
564
 
     settings.setValue(&quot;DownloadLimit&quot;, downloadLimitSlider-&gt;value());
565
 
 
566
 
     <span class="comment">// Store data on all known torrents</span>
567
 
     settings.beginWriteArray(&quot;Torrents&quot;);
568
 
     for (int i = 0; i &lt; jobs.size(); ++i) {
569
 
         settings.setArrayIndex(i);
570
 
         settings.setValue(&quot;sourceFileName&quot;, jobs.at(i).torrentFileName);
571
 
         settings.setValue(&quot;destinationFolder&quot;, jobs.at(i).destinationDirectory);
572
 
         settings.setValue(&quot;uploadedBytes&quot;, jobs.at(i).client-&gt;uploadedBytes());
573
 
         settings.setValue(&quot;downloadedBytes&quot;, jobs.at(i).client-&gt;downloadedBytes());
574
 
         settings.setValue(&quot;resumeState&quot;, jobs.at(i).client-&gt;dumpedState());
575
 
     }
576
 
     settings.endArray();
577
 
     settings.sync();
578
 
 }
579
 
 
580
 
 void MainWindow::updateState(TorrentClient::State)
581
 
 {
582
 
     <span class="comment">// Update the state string whenever the client's state changes.</span>
583
 
     TorrentClient *client = qobject_cast&lt;TorrentClient *&gt;(sender());
584
 
     int row = rowOfClient(client);
585
 
     QTreeWidgetItem *item = torrentView-&gt;topLevelItem(row);
586
 
     if (item) {
587
 
         item-&gt;setToolTip(0, tr(&quot;Torrent: %1&lt;br&gt;Destination: %2&lt;br&gt;State: %3&quot;)
588
 
                          .arg(jobs.at(row).torrentFileName)
589
 
                          .arg(jobs.at(row).destinationDirectory)
590
 
                          .arg(client-&gt;stateString()));
591
 
 
592
 
         item-&gt;setText(5, client-&gt;stateString());
593
 
     }
594
 
     setActionsEnabled();
595
 
 }
596
 
 
597
 
 void MainWindow::updatePeerInfo()
598
 
 {
599
 
     <span class="comment">// Update the number of connected, visited, seed and leecher peers.</span>
600
 
     TorrentClient *client = qobject_cast&lt;TorrentClient *&gt;(sender());
601
 
     int row = rowOfClient(client);
602
 
 
603
 
     QTreeWidgetItem *item = torrentView-&gt;topLevelItem(row);
604
 
     item-&gt;setText(1, tr(&quot;%1/%2&quot;).arg(client-&gt;connectedPeerCount())
605
 
                   .arg(client-&gt;seedCount()));
606
 
 }
607
 
 
608
 
 void MainWindow::updateProgress(int percent)
609
 
 {
610
 
     TorrentClient *client = qobject_cast&lt;TorrentClient *&gt;(sender());
611
 
     int row = rowOfClient(client);
612
 
 
613
 
     <span class="comment">// Update the progressbar.</span>
614
 
     QTreeWidgetItem *item = torrentView-&gt;topLevelItem(row);
615
 
     if (item)
616
 
         item-&gt;setText(2, QString::number(percent));
617
 
 }
618
 
 
619
 
 void MainWindow::setActionsEnabled()
620
 
 {
621
 
     <span class="comment">// Find the view item and client for the current row, and update</span>
622
 
     <span class="comment">// the states of the actions.</span>
623
 
     QTreeWidgetItem *item = 0;
624
 
     if (!torrentView-&gt;selectedItems().isEmpty())
625
 
         item = torrentView-&gt;selectedItems().first();
626
 
     TorrentClient *client = item ? jobs.at(torrentView-&gt;indexOfTopLevelItem(item)).client : 0;
627
 
     bool pauseEnabled = client &amp;&amp; ((client-&gt;state() == TorrentClient::Paused)
628
 
                                        ||  (client-&gt;state() &gt; TorrentClient::Preparing));
629
 
 
630
 
     removeTorrentAction-&gt;setEnabled(item != 0);
631
 
     pauseTorrentAction-&gt;setEnabled(item != 0 &amp;&amp; pauseEnabled);
632
 
 
633
 
     if (client &amp;&amp; client-&gt;state() == TorrentClient::Paused) {
634
 
         pauseTorrentAction-&gt;setIcon(QIcon(&quot;:/icons/player_play.png&quot;));
635
 
         pauseTorrentAction-&gt;setText(tr(&quot;Resume torrent&quot;));
636
 
     } else {
637
 
         pauseTorrentAction-&gt;setIcon(QIcon(&quot;:/icons/player_pause.png&quot;));
638
 
         pauseTorrentAction-&gt;setText(tr(&quot;Pause torrent&quot;));
639
 
     }
640
 
 
641
 
     int row = torrentView-&gt;indexOfTopLevelItem(item);
642
 
     upActionTool-&gt;setEnabled(item &amp;&amp; row != 0);
643
 
     downActionTool-&gt;setEnabled(item &amp;&amp; row != jobs.size() - 1);
644
 
 }
645
 
 
646
 
 void MainWindow::updateDownloadRate(int bytesPerSecond)
647
 
 {
648
 
     <span class="comment">// Update the download rate.</span>
649
 
     TorrentClient *client = qobject_cast&lt;TorrentClient *&gt;(sender());
650
 
     int row = rowOfClient(client);
651
 
     QString num;
652
 
     num.sprintf(&quot;%.1f KB/s&quot;, bytesPerSecond / 1024.0);
653
 
     torrentView-&gt;topLevelItem(row)-&gt;setText(3, num);
654
 
 
655
 
     if (!saveChanges) {
656
 
         saveChanges = true;
657
 
         QTimer::singleShot(5000, this, SLOT(saveSettings()));
658
 
     }
659
 
 }
660
 
 
661
 
 void MainWindow::updateUploadRate(int bytesPerSecond)
662
 
 {
663
 
     <span class="comment">// Update the upload rate.</span>
664
 
     TorrentClient *client = qobject_cast&lt;TorrentClient *&gt;(sender());
665
 
     int row = rowOfClient(client);
666
 
     QString num;
667
 
     num.sprintf(&quot;%.1f KB/s&quot;, bytesPerSecond / 1024.0);
668
 
     torrentView-&gt;topLevelItem(row)-&gt;setText(4, num);
669
 
 
670
 
     if (!saveChanges) {
671
 
         saveChanges = true;
672
 
         QTimer::singleShot(5000, this, SLOT(saveSettings()));
673
 
     }
674
 
 }
675
 
 
676
 
 void MainWindow::pauseTorrent()
677
 
 {
678
 
     <span class="comment">// Pause or unpause the current torrent.</span>
679
 
     int row = torrentView-&gt;indexOfTopLevelItem(torrentView-&gt;currentItem());
680
 
     TorrentClient *client = jobs.at(row).client;
681
 
     client-&gt;setPaused(client-&gt;state() != TorrentClient::Paused);
682
 
     setActionsEnabled();
683
 
 }
684
 
 
685
 
 void MainWindow::moveTorrentUp()
686
 
 {
687
 
     QTreeWidgetItem *item = torrentView-&gt;currentItem();
688
 
     int row = torrentView-&gt;indexOfTopLevelItem(item);
689
 
     if (row == 0)
690
 
         return;
691
 
 
692
 
     Job tmp = jobs.at(row - 1);
693
 
     jobs[row - 1] = jobs[row];
694
 
     jobs[row] = tmp;
695
 
 
696
 
     QTreeWidgetItem *itemAbove = torrentView-&gt;takeTopLevelItem(row - 1);
697
 
     torrentView-&gt;insertTopLevelItem(row, itemAbove);
698
 
     setActionsEnabled();
699
 
 }
700
 
 
701
 
 void MainWindow::moveTorrentDown()
702
 
 {
703
 
     QTreeWidgetItem *item = torrentView-&gt;currentItem();
704
 
     int row = torrentView-&gt;indexOfTopLevelItem(item);
705
 
     if (row == jobs.size() - 1)
706
 
         return;
707
 
 
708
 
     Job tmp = jobs.at(row + 1);
709
 
     jobs[row + 1] = jobs[row];
710
 
     jobs[row] = tmp;
711
 
 
712
 
     QTreeWidgetItem *itemAbove = torrentView-&gt;takeTopLevelItem(row + 1);
713
 
     torrentView-&gt;insertTopLevelItem(row, itemAbove);
714
 
     setActionsEnabled();
715
 
 }
716
 
 
717
 
 static int rateFromValue(int value)
718
 
 {
719
 
     int rate = 0;
720
 
     if (value &gt;= 0 &amp;&amp; value &lt; 250) {
721
 
         rate = 1 + int(value * 0.124);
722
 
     } else if (value &lt; 500) {
723
 
         rate = 32 + int((value - 250) * 0.384);
724
 
     } else if (value &lt; 750) {
725
 
         rate = 128 + int((value - 500) * 1.536);
726
 
     } else {
727
 
         rate = 512 + int((value - 750) * 6.1445);
728
 
     }
729
 
     return rate;
730
 
 }
731
 
 
732
 
 void MainWindow::setUploadLimit(int value)
733
 
 {
734
 
     int rate = rateFromValue(value);
735
 
     uploadLimitLabel-&gt;setText(tr(&quot;%1 KB/s&quot;).arg(QString().sprintf(&quot;%4d&quot;, rate)));
736
 
     RateController::instance()-&gt;setUploadLimit(rate * 1024);
737
 
 }
738
 
 
739
 
 void MainWindow::setDownloadLimit(int value)
740
 
 {
741
 
     int rate = rateFromValue(value);
742
 
     downloadLimitLabel-&gt;setText(tr(&quot;%1 KB/s&quot;).arg(QString().sprintf(&quot;%4d&quot;, rate)));
743
 
     RateController::instance()-&gt;setDownloadLimit(rate * 1024);
744
 
 }
745
 
 
746
 
 void MainWindow::about()
747
 
 {
748
 
     QLabel *icon = new QLabel;
749
 
     icon-&gt;setPixmap(QPixmap(&quot;:/icons/peertopeer.png&quot;));
750
 
 
751
 
     QLabel *text = new QLabel;
752
 
     text-&gt;setWordWrap(true);
753
 
     text-&gt;setText(&quot;&lt;p&gt;The &lt;b&gt;Torrent Client&lt;/b&gt; example demonstrates how to&quot;
754
 
                   &quot; write a complete peer-to-peer file sharing&quot;
755
 
                   &quot; application using Qt's network and thread classes.&lt;/p&gt;&quot;
756
 
                   &quot;&lt;p&gt;This feature complete client implementation of&quot;
757
 
                   &quot; the BitTorrent protocol can efficiently&quot;
758
 
                   &quot; maintain several hundred network connections&quot;
759
 
                   &quot; simultaneously.&lt;/p&gt;&quot;);
760
 
 
761
 
     QPushButton *quitButton = new QPushButton(&quot;OK&quot;);
762
 
 
763
 
     QHBoxLayout *topLayout = new QHBoxLayout;
764
 
     topLayout-&gt;setMargin(10);
765
 
     topLayout-&gt;setSpacing(10);
766
 
     topLayout-&gt;addWidget(icon);
767
 
     topLayout-&gt;addWidget(text);
768
 
 
769
 
     QHBoxLayout *bottomLayout = new QHBoxLayout;
770
 
     bottomLayout-&gt;addStretch();
771
 
     bottomLayout-&gt;addWidget(quitButton);
772
 
     bottomLayout-&gt;addStretch();
773
 
 
774
 
     QVBoxLayout *mainLayout = new QVBoxLayout;
775
 
     mainLayout-&gt;addLayout(topLayout);
776
 
     mainLayout-&gt;addLayout(bottomLayout);
777
 
 
778
 
     QDialog about(this);
779
 
     about.setModal(true);
780
 
     about.setWindowTitle(tr(&quot;About Torrent Client&quot;));
781
 
     about.setLayout(mainLayout);
782
 
 
783
 
     connect(quitButton, SIGNAL(clicked()), &amp;about, SLOT(close()));
784
 
 
785
 
     about.exec();
786
 
 }
787
 
 
788
 
 void MainWindow::acceptFileDrop(const QString &amp;fileName)
789
 
 {
790
 
     <span class="comment">// Create and show the &quot;Add Torrent&quot; dialog.</span>
791
 
     AddTorrentDialog *addTorrentDialog = new AddTorrentDialog;
792
 
     lastDirectory = QFileInfo(fileName).absolutePath();
793
 
     addTorrentDialog-&gt;setTorrent(fileName);
794
 
     addTorrentDialog-&gt;deleteLater();
795
 
     if (!addTorrentDialog-&gt;exec())
796
 
         return;
797
 
 
798
 
     <span class="comment">// Add the torrent to our list of downloads.</span>
799
 
     addTorrent(fileName, addTorrentDialog-&gt;destinationFolder());
800
 
     saveSettings();
801
 
 }
802
 
 
803
 
 void MainWindow::closeEvent(QCloseEvent *)
804
 
 {
805
 
     if (jobs.isEmpty())
806
 
         return;
807
 
 
808
 
     <span class="comment">// Save upload / download numbers.</span>
809
 
     saveSettings();
810
 
     saveChanges = false;
811
 
 
812
 
     quitDialog = new QProgressDialog(tr(&quot;Disconnecting from trackers&quot;), tr(&quot;Abort&quot;), 0, jobsToStop, this);
813
 
 
814
 
     <span class="comment">// Stop all clients, remove the rows from the view and wait for</span>
815
 
     <span class="comment">// them to signal that they have stopped.</span>
816
 
     jobsToStop = 0;
817
 
     jobsStopped = 0;
818
 
     foreach (Job job, jobs) {
819
 
         ++jobsToStop;
820
 
         TorrentClient *client = job.client;
821
 
         client-&gt;disconnect();
822
 
         connect(client, SIGNAL(stopped()), this, SLOT(torrentStopped()));
823
 
         client-&gt;stop();
824
 
         delete torrentView-&gt;takeTopLevelItem(0);
825
 
     }
826
 
 
827
 
     if (jobsToStop &gt; jobsStopped)
828
 
         quitDialog-&gt;exec();
829
 
     quitDialog-&gt;deleteLater();
830
 
     quitDialog = 0;
831
 
 }
832
 
 
833
 
 TorrentView::TorrentView(QWidget *parent)
834
 
     : QTreeWidget(parent)
835
 
 {
836
 
     setAcceptDrops(true);
837
 
 }
838
 
 
839
 
 void TorrentView::dragMoveEvent(QDragMoveEvent *event)
840
 
 {
841
 
     <span class="comment">// Accept file actions with a '.torrent' extension.</span>
842
 
     QUrl url(event-&gt;mimeData()-&gt;text());
843
 
     if (url.isValid() &amp;&amp; url.scheme().toLower() == &quot;file&quot;
844
 
             &amp;&amp; url.path().toLower().endsWith(&quot;.torrent&quot;))
845
 
         event-&gt;acceptProposedAction();
846
 
 }
847
 
 
848
 
 void TorrentView::dropEvent(QDropEvent *event)
849
 
 {
850
 
     <span class="comment">// Accept drops if the file has a '.torrent' extension and it</span>
851
 
     <span class="comment">// exists.</span>
852
 
     QString fileName = QUrl(event-&gt;mimeData()-&gt;text()).path();
853
 
     if (QFile::exists(fileName) &amp;&amp; fileName.toLower().endsWith(&quot;.torrent&quot;))
854
 
         emit fileDropped(fileName);
855
 
 }
856
 
 
857
 
 #include &quot;mainwindow.moc&quot;</pre>
858
 
</div>
859
 
<!-- @@@network/torrent/mainwindow.cpp -->
860
 
        <div class="feedback t_button">
861
 
          [+] Documentation Feedback</div>
862
 
      </div>
863
 
    </div>
864
 
    </div> 
865
 
    <div class="ft">
866
 
      <span></span>
867
 
    </div>
868
 
  </div> 
869
 
  <div class="footer">
870
 
    <p>
871
 
      <acronym title="Copyright">&copy;</acronym> 2008-2010 Nokia Corporation and/or its
872
 
      subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation 
873
 
      in Finland and/or other countries worldwide.</p>
874
 
    <p>
875
 
      All other trademarks are property of their respective owners. <a title="Privacy Policy"
876
 
        href="http://qt.nokia.com/about/privacy-policy">Privacy Policy</a></p>
877
 
    <br />
878
 
    <p>
879
 
      Licensees holding valid Qt Commercial licenses may use this document in accordance with the      Qt Commercial License Agreement provided with the Software or, alternatively, in accordance      with the terms contained in a written agreement between you and Nokia.</p>
880
 
    <p>
881
 
      Alternatively, this document may be used under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU
882
 
      Free Documentation License version 1.3</a>
883
 
      as published by the Free Software Foundation.</p>
884
 
  </div>
885
 
  <div id="feedbackBox">
886
 
      <div id="feedcloseX" class="feedclose t_button">X</div>
887
 
    <form id="feedform" action="http://doc.qt.nokia.com/docFeedbck/feedback.php" method="get">
888
 
      <p id="noteHead">Thank you for giving your feedback.</p> <p class="note">Make sure it is related to this specific page. For more general bugs and 
889
 
      requests, please use the <a href="http://bugreports.qt.nokia.com/secure/Dashboard.jspa">Qt Bug Tracker</a>.</p>
890
 
      <p><textarea id="feedbox" name="feedText" rows="5" cols="40"></textarea></p>
891
 
      <p><input id="feedsubmit" class="feedclose" type="submit" name="feedback" /></p>
892
 
    </form>
893
 
  </div>
894
 
  <div id="blurpage">
895
 
  </div>
896
 
</body>
897
 
</html>