~ubuntu-branches/ubuntu/lucid/ktorrent/lucid

« back to all changes in this revision

Viewing changes to libbtcore/torrent/torrentfile.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2009-02-16 18:37:14 UTC
  • mfrom: (1.1.25 upstream) (0.4.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090216183714-52tf47jrnmk4xkmp
Tags: 3.2+dfsg.1-2ubuntu1
* Merge with Debian, remaining changes: (LP: #296433)
  - Use Kubuntu's kde4.mk
  - Build-depend on libboost-serialization1.35-dev since unversioned -dev is
    in universe
  - Change plasma-applet-ktorrent to plasma-widget-ktorrent since we're
    supposed to call them widgets for the users

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include <util/functions.h>
27
27
#include <diskio/chunkmanager.h>
28
28
 
 
29
 
29
30
namespace bt
30
31
{
 
32
        TorrentFile TorrentFile::null(0);
31
33
 
32
 
        TorrentFile::TorrentFile() : TorrentFileInterface(0,QString(),0),missing(false),filetype(UNKNOWN)
 
34
        TorrentFile::TorrentFile(Torrent* tor) : TorrentFileInterface(0,QString(),0),tor(tor),missing(false),filetype(UNKNOWN)
33
35
        {}
34
36
 
35
 
        TorrentFile::TorrentFile(Uint32 index,const QString & path,
 
37
        TorrentFile::TorrentFile(Torrent* tor,Uint32 index,const QString & path,
36
38
                                                         Uint64 off,Uint64 size,Uint64 chunk_size)
37
 
        : TorrentFileInterface(index,path,size),cache_offset(off),missing(false),filetype(UNKNOWN)
 
39
        : TorrentFileInterface(index,path,size),tor(tor),cache_offset(off),missing(false),filetype(UNKNOWN)
38
40
        {
39
41
                first_chunk = off / chunk_size;
40
42
                first_chunk_off = off % chunk_size;
60
62
                last_chunk_size = tf.getLastChunkSize();
61
63
                old_priority = priority = tf.getPriority();
62
64
                missing = tf.isMissing();
 
65
                tor = tf.tor;
63
66
                filetype = UNKNOWN;
64
67
        }
65
68
 
70
73
        {
71
74
                if (priority != EXCLUDED && dnd)
72
75
                {
73
 
                        if(m_emitDlStatusChanged)
 
76
                        if (m_emitDlStatusChanged)
74
77
                                old_priority = priority;
75
78
                        
76
79
                        priority = EXCLUDED;
77
80
                        
78
81
                        if(m_emitDlStatusChanged)
79
 
                                emit downloadPriorityChanged(this,priority,old_priority);       
 
82
                                tor->downloadPriorityChanged(this,priority,old_priority);       
80
83
                }
81
84
                if (priority == EXCLUDED && (!dnd))
82
85
                {
83
 
                        if(m_emitDlStatusChanged)
 
86
                        if (m_emitDlStatusChanged)
84
87
                                old_priority = priority;
85
88
                        
86
89
                        priority = NORMAL_PRIORITY;
87
90
                        
88
91
                        if(m_emitDlStatusChanged)
89
 
                                emit downloadPriorityChanged(this,priority,old_priority);
 
92
                                tor->downloadPriorityChanged(this,priority,old_priority);
90
93
                }
91
94
        }
92
95
        
94
97
        {
95
98
                // only emit when old_priority is not equal to the new priority
96
99
                if (priority != old_priority)
97
 
                        emit downloadPriorityChanged(this,priority,old_priority);
 
100
                        tor->downloadPriorityChanged(this,priority,old_priority);
98
101
        }
99
102
 
100
103
 
116
119
 
117
120
        void TorrentFile::setPriority(Priority newpriority)
118
121
        {
119
 
                if(priority != newpriority)
 
122
                if (priority != newpriority)
120
123
                {
121
124
                        if (priority == EXCLUDED)
122
125
                        {
123
126
                                setDoNotDownload(false);
124
127
                        }
 
128
                        
125
129
                        if (newpriority == EXCLUDED)
126
130
                        {
127
131
                                setDoNotDownload(true);
 
132
                                tor->filePercentageChanged(this,getDownloadPercentage());
128
133
                        }
129
134
                        else
130
135
                        {
131
136
                                old_priority = priority;
132
137
                                priority = newpriority;
133
 
                                emit downloadPriorityChanged(this,newpriority,old_priority);
 
138
                                tor->downloadPriorityChanged(this,newpriority,old_priority);
 
139
                                
 
140
                                // make sure percentages are updated properly
 
141
                                if (old_priority == ONLY_SEED_PRIORITY || newpriority == ONLY_SEED_PRIORITY || old_priority == EXCLUDED)
 
142
                                {
 
143
                                        tor->filePercentageChanged(this,getDownloadPercentage());
 
144
                                }
134
145
                        }
135
146
                }
136
147
        }
147
158
                last_chunk_size = tf.getLastChunkSize();
148
159
                priority = tf.getPriority();
149
160
                missing = tf.isMissing();
 
161
                tor = tf.tor;
150
162
                return *this;
151
163
        }
152
 
 
153
 
        TorrentFile TorrentFile::null;
154
 
 
155
164
        
156
165
        Uint64 TorrentFile::fileOffset(Uint32 cindex,Uint64 chunk_size) const
157
166
        {
173
182
        void TorrentFile::updateNumDownloadedChunks(ChunkManager & cman)
174
183
        {
175
184
                const BitSet & bs = cman.getBitSet();
176
 
                float p = getDownloadPercentage();
 
185
                Uint32 old_chunk_count = num_chunks_downloaded;
177
186
                num_chunks_downloaded = 0;
178
187
                
179
188
                Uint32 preview_range = cman.previewChunkRangeSize(*this);
192
201
                }
193
202
                preview = isMultimedia() && preview;
194
203
                
195
 
                float np = getDownloadPercentage();
196
 
                if (fabs(np - p) >= 0.01f)
197
 
                        downloadPercentageChanged(np);
 
204
                if (num_chunks_downloaded != old_chunk_count)
 
205
                        tor->filePercentageChanged(this,getDownloadPercentage());
198
206
                
199
207
                if (prev != preview)
200
 
                        previewAvailable(preview);
 
208
                        tor->filePreviewChanged(this,preview);
201
209
        }
202
210
        
203
211
}