(trunk qt) add popup notification for when torrents finish downloading.
This commit is contained in:
parent
14310a7300
commit
0b2247cc7b
36
qt/app.cc
36
qt/app.cc
|
@ -254,8 +254,8 @@ MyApp :: MyApp( int& argc, char ** argv ):
|
|||
std::cerr << "couldn't register " << DBUS_OBJECT_PATH << std::endl;
|
||||
}
|
||||
|
||||
/* these two functions are for popping up desktop notification
|
||||
* when new torrents are added */
|
||||
/* these functions are for popping up desktop notifications */
|
||||
|
||||
void
|
||||
MyApp :: onTorrentsAdded( QSet<int> torrents )
|
||||
{
|
||||
|
@ -265,12 +265,31 @@ MyApp :: onTorrentsAdded( QSet<int> torrents )
|
|||
foreach( int id, torrents )
|
||||
{
|
||||
Torrent * tor = myModel->getTorrentFromId( id );
|
||||
if( !tor->name().isEmpty( ) )
|
||||
onNewTorrentChanged( id );
|
||||
else // wait until the torrent's INFO fields are loaded
|
||||
std::cerr << "torrent added: " << qPrintable(tor->name()) << std::endl;
|
||||
|
||||
if( tor->name().isEmpty( ) ) // wait until the torrent's INFO fields are loaded
|
||||
connect( tor, SIGNAL(torrentChanged(int)), this, SLOT(onNewTorrentChanged(int)) );
|
||||
else {
|
||||
onNewTorrentChanged( id );
|
||||
if( !tor->isSeed( ) )
|
||||
connect( tor, SIGNAL(torrentCompleted(int)), this, SLOT(onTorrentCompleted(int)) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MyApp :: onTorrentCompleted( int id )
|
||||
{
|
||||
Torrent * tor = myModel->getTorrentFromId( id );
|
||||
|
||||
if( tor && !tor->name().isEmpty() )
|
||||
{
|
||||
notify( tr( "Torrent Completed" ), tor->name( ) );
|
||||
|
||||
disconnect( tor, SIGNAL(torrentCompleted(int)), this, SLOT(onTorrentCompleted(int)) );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MyApp :: onNewTorrentChanged( int id )
|
||||
{
|
||||
|
@ -283,9 +302,16 @@ MyApp :: onNewTorrentChanged( int id )
|
|||
notify( tr( "Torrent Added" ), tor->name( ) );
|
||||
|
||||
disconnect( tor, SIGNAL(torrentChanged(int)), this, SLOT(onNewTorrentChanged(int)) );
|
||||
|
||||
if( !tor->isSeed( ) )
|
||||
connect( tor, SIGNAL(torrentCompleted(int)), this, SLOT(onTorrentCompleted(int)) );
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
void
|
||||
MyApp :: consentGiven( )
|
||||
{
|
||||
|
|
1
qt/app.h
1
qt/app.h
|
@ -61,6 +61,7 @@ class MyApp: public QApplication
|
|||
void refreshPref( int key );
|
||||
void refreshTorrents( );
|
||||
void onTorrentsAdded( QSet<int> );
|
||||
void onTorrentCompleted( int );
|
||||
void onNewTorrentChanged( int );
|
||||
|
||||
public slots:
|
||||
|
|
|
@ -454,6 +454,8 @@ void
|
|||
Torrent :: update( tr_benc * d )
|
||||
{
|
||||
bool changed = false;
|
||||
const bool was_seed = isSeed( );
|
||||
const uint64_t old_verified_size = haveVerified( );
|
||||
|
||||
for( int i=0; i<PROPERTY_COUNT; ++i )
|
||||
{
|
||||
|
@ -687,6 +689,9 @@ Torrent :: update( tr_benc * d )
|
|||
|
||||
if( changed )
|
||||
emit torrentChanged( id( ) );
|
||||
|
||||
if( !was_seed && isSeed() && (old_verified_size>0) )
|
||||
emit torrentCompleted( id( ) );
|
||||
}
|
||||
|
||||
QString
|
||||
|
|
|
@ -182,6 +182,7 @@ class Torrent: public QObject
|
|||
|
||||
signals:
|
||||
void torrentChanged( int id );
|
||||
void torrentCompleted( int id );
|
||||
|
||||
private:
|
||||
|
||||
|
|
Loading…
Reference in New Issue