(trunk qt) add popup notification for when torrents finish downloading.

This commit is contained in:
Jordan Lee 2011-07-26 02:56:30 +00:00
parent 14310a7300
commit 0b2247cc7b
4 changed files with 38 additions and 5 deletions

View File

@ -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( )
{

View File

@ -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:

View File

@ -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

View File

@ -182,6 +182,7 @@ class Torrent: public QObject
signals:
void torrentChanged( int id );
void torrentCompleted( int id );
private: