Changeset 11085


Ignore:
Timestamp:
Aug 1, 2010, 3:47:42 PM (12 years ago)
Author:
charles
Message:

(trunk qt) #3469 "Qt client should have desktop notification for added torrents" -- done.

Location:
trunk/qt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/app.cc

    r11083 r11085  
    250250MyApp :: torrentsAdded( QSet<int> torrents )
    251251{
    252     myAddedTorrents += torrents;
    253 std::cerr << "added count is " << myAddedTorrents.size() << std::endl;
     252    foreach( int id, torrents )
     253    {
     254        Torrent * tor = myModel->getTorrentFromId( id );
     255        if( !tor->name().isEmpty( ) )
     256            torrentChanged( id );
     257        else // wait until the torrent's INFO fields are loaded
     258            connect( tor, SIGNAL(torrentChanged(int)), this, SLOT(torrentChanged(int)) );
     259    }
     260}
     261
     262void
     263MyApp :: torrentChanged( int id )
     264{
     265    Torrent * tor = myModel->getTorrentFromId( id );
     266
     267    if( tor && !tor->name().isEmpty() )
     268    {
     269        const int age_secs = tor->dateAdded().secsTo(QDateTime::currentDateTime());
     270        if( age_secs < 30 )
     271            notify( tr( "Torrent Added" ), tor->name( ) );
     272
     273        disconnect( tor, SIGNAL(torrentChanged(int)), this, SLOT(torrentChanged(int)) );
     274    }
    254275}
    255276
     
    375396
    376397bool
    377 MyApp :: notify( const QString& title, const QString& body, int timeout_msec ) const
     398MyApp :: notify( const QString& title, const QString& body ) const
    378399{
    379400    const QString dbusServiceName = "org.freedesktop.Notifications";
     
    440461    tr_optind = 1;
    441462    MyApp app( argc, argv );
    442     app.notify( "hello world", "this is a test" );
    443463    return app.exec( );
    444464}
  • trunk/qt/app.h

    r11083 r11085  
    3535    public:
    3636        void raise( );
    37         bool notify( const QString& title, const QString& body, int timeout_msec=-1 ) const;
     37        bool notify( const QString& title, const QString& body ) const;
    3838
    3939    public:
     
    5050        QTimer mySessionTimer;
    5151        time_t myLastFullUpdateTime;
    52         QSet<int> myAddedTorrents;
    5352
    5453    private slots:
     
    5857        void refreshTorrents( );
    5958        void torrentsAdded( QSet<int> );
     59        void torrentChanged( int );
    6060
    6161    public slots:
Note: See TracChangeset for help on using the changeset viewer.