From 040bc734f82b65ad7bab0b07cc6db39078ea3349 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 1 Aug 2010 14:51:28 +0000 Subject: [PATCH] (trunk) fix a documentation error in the RPC spec. lastAnnounceResult is a string, not an int --- doc/rpc-spec.txt | 2 +- qt/app.cc | 38 ++++++++++++++++++++++++++++++++++++++ qt/app.h | 4 ++++ qt/torrent.cc | 4 ++-- qt/torrent.h | 2 +- qt/tracker-delegate.cc | 2 +- 6 files changed, 47 insertions(+), 5 deletions(-) diff --git a/doc/rpc-spec.txt b/doc/rpc-spec.txt index c47b12afa..ac1bd0447 100644 --- a/doc/rpc-spec.txt +++ b/doc/rpc-spec.txt @@ -276,7 +276,7 @@ | id | number | tr_tracker_stat | isBackup | boolean | tr_tracker_stat | lastAnnouncePeerCount | number | tr_tracker_stat - | lastAnnounceResult | number | tr_tracker_stat + | lastAnnounceResult | string | tr_tracker_stat | lastAnnounceStartTime | number | tr_tracker_stat | lastAnnounceSucceeded | boolean | tr_tracker_stat | lastAnnounceTime | number | tr_tracker_stat diff --git a/qt/app.cc b/qt/app.cc index dc0a63b7d..04b1cf579 100644 --- a/qt/app.cc +++ b/qt/app.cc @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -167,6 +168,7 @@ MyApp :: MyApp( int& argc, char ** argv ): connect( mySession, SIGNAL(sourceChanged()), this, SLOT(onSessionSourceChanged()) ); // when the model sees a torrent for the first time, ask the session for full info on it connect( myModel, SIGNAL(torrentsAdded(QSet)), mySession, SLOT(initTorrents(QSet)) ); + connect( myModel, SIGNAL(torrentsAdded(QSet)), this, SLOT(torrentsAdded(QSet)) ); mySession->initTorrents( ); mySession->refreshSessionStats( ); @@ -244,6 +246,13 @@ MyApp :: MyApp( int& argc, char ** argv ): std::cerr << qPrintable(bus.lastError().message()) << std::endl; } +void +MyApp :: torrentsAdded( QSet torrents ) +{ + myAddedTorrents += torrents; +std::cerr << "added count is " << myAddedTorrents.size() << std::endl; +} + void MyApp :: consentGiven( ) { @@ -354,12 +363,40 @@ MyApp :: addTorrent( const QString& key ) raise( ); } +/*** +**** +***/ + void MyApp :: raise( ) { QApplication :: alert ( myWindow ); } +bool +MyApp :: notify( const QString& title, const QString& body, int timeout_msec ) const +{ + const QString dbusServiceName = "org.freedesktop.Notifications"; + const QString dbusInterfaceName = "org.freedesktop.Notifications"; + const QString dbusPath = "/org/freedesktop/Notifications"; + + QDBusMessage m = QDBusMessage::createMethodCall(dbusServiceName, dbusPath, dbusInterfaceName, "Notify"); + QList args; + args.append( "Transmission" ); // app_name + args.append( 0U ); // replaces_id + args.append( "transmission" ); // icon + args.append( title ); // summary + args.append( body ); // body + args.append( QStringList( ) ); // actions - unused for plain passive popups + args.append( QVariantMap( ) ); // hints - unused atm + args.append( int32_t(-1) ); // use the default timeout period + m.setArguments( args ); + QDBusMessage replyMsg = QDBusConnection::sessionBus().call(m); + //std::cerr << qPrintable(replyMsg.errorName()) << std::endl; + //std::cerr << qPrintable(replyMsg.errorMessage()) << std::endl; + return (replyMsg.type() == QDBusMessage::ReplyMessage) && !replyMsg.arguments().isEmpty(); +} + /*** **** ***/ @@ -402,5 +439,6 @@ main( int argc, char * argv[] ) tr_optind = 1; MyApp app( argc, argv ); + app.notify( "hello world", "this is a test" ); return app.exec( ); } diff --git a/qt/app.h b/qt/app.h index 630661440..d7a4a17fc 100644 --- a/qt/app.h +++ b/qt/app.h @@ -14,6 +14,7 @@ #define QTR_APP_H #include +#include #include #include "favicon.h" @@ -33,6 +34,7 @@ class MyApp: public QApplication public: void raise( ); + bool notify( const QString& title, const QString& body, int timeout_msec=-1 ) const; public: Favicons favicons; @@ -47,12 +49,14 @@ class MyApp: public QApplication QTimer myStatsTimer; QTimer mySessionTimer; time_t myLastFullUpdateTime; + QSet myAddedTorrents; private slots: void consentGiven( ); void onSessionSourceChanged( ); void refreshPref( int key ); void refreshTorrents( ); + void torrentsAdded( QSet ); public slots: void addTorrent( const QString& ); diff --git a/qt/torrent.cc b/qt/torrent.cc index b0bfd8b21..8241a981f 100644 --- a/qt/torrent.cc +++ b/qt/torrent.cc @@ -586,8 +586,8 @@ Torrent :: update( tr_benc * d ) trackerStat.isBackup = b; if( tr_bencDictFindInt( child, "lastAnnouncePeerCount", &i ) ) trackerStat.lastAnnouncePeerCount = i; - if( tr_bencDictFindInt( child, "lastAnnounceResult", &i ) ) - trackerStat.lastAnnounceResult = i; + if( tr_bencDictFindStr( child, "lastAnnounceResult", &str ) ) + trackerStat.lastAnnounceResult = str; if( tr_bencDictFindInt( child, "lastAnnounceStartTime", &i ) ) trackerStat.lastAnnounceStartTime = i; if( tr_bencDictFindBool( child, "lastAnnounceSucceeded", &b ) ) diff --git a/qt/torrent.h b/qt/torrent.h index 2536b1731..a2e6594d3 100644 --- a/qt/torrent.h +++ b/qt/torrent.h @@ -71,7 +71,7 @@ struct TrackerStat int id; bool isBackup; int lastAnnouncePeerCount; - int lastAnnounceResult; + QString lastAnnounceResult; int lastAnnounceStartTime; bool lastAnnounceSucceeded; int lastAnnounceTime; diff --git a/qt/tracker-delegate.cc b/qt/tracker-delegate.cc index 2adb73b13..6a68cbac8 100644 --- a/qt/tracker-delegate.cc +++ b/qt/tracker-delegate.cc @@ -184,7 +184,7 @@ TrackerDelegate :: getText( const TrackerInfo& inf ) const { str += tr( "Got an error %1\"%2\"%3 %4 ago" ) .arg( err_markup_begin ) - .arg( tstr ) + .arg( inf.st.lastAnnounceResult ) .arg( err_markup_end ) .arg( tstr ); } -- 2.40.0