Server methods to store/get options
authordeztructor <denis.zalewsky@gmail.com>
Tue, 24 Nov 2009 08:16:11 +0000 (08:16 +0000)
committerdeztructor <denis.zalewsky@gmail.com>
Tue, 24 Nov 2009 08:16:11 +0000 (08:16 +0000)
git-svn-id: file:///svnroot/qtrapids/trunk@49 42ac0dd5-4c8c-4c71-bb3e-ecdfe252ffda

dbus/com.ixonos.qtrapids.xml
src/server/ServerDb.hpp
src/server/TorrentSession.cpp
src/server/TorrentSession.hpp

index 1496a78..520085d 100644 (file)
                   value="qtrapids::ParamsMap_t"/>
     </method>
 
                   value="qtrapids::ParamsMap_t"/>
     </method>
 
-    <method name="setOption">
-      <arg type="s" direction="in" name="name"/>
-      <arg type="s" direction="in" name="value"/>
+    <method name="setOptions">
+      <arg type="a{ss}" direction="in" name="options"/>
+      <annotation name="com.trolltech.QtDBus.QtTypeName.In0" 
+                  value="qtrapids::ParamsMap_t"/>
     </method>
 
   </interface>
     </method>
 
   </interface>
index 9bda677..fa31059 100644 (file)
@@ -34,6 +34,10 @@ public:
 
        }
 
 
        }
 
+       static QString getTorrentsSubDir() {
+               return QString(".") + appName();
+       }
+
        QString getDownloadDir() const {
                QString default_dir(QDir::home().absolutePath());
                QString v = getParamAndStore("download/directory", default_dir).toString();
        QString getDownloadDir() const {
                QString default_dir(QDir::home().absolutePath());
                QString v = getParamAndStore("download/directory", default_dir).toString();
@@ -45,8 +49,30 @@ public:
                }
        }
 
                }
        }
 
-       static QString getTorrentsSubDir() {
-               return QString(".") + appName();
+       ports_range_t getListenPorts() const {
+
+               ports_range_t default_ports(13131, 13132);
+               default_ports.first = getParamAndStore("net/listen_range_begin", default_ports.first).toUInt();
+               default_ports.second = getParamAndStore("net/listen_range_end", default_ports.second).toUInt();
+               return default_ports;
+       }
+
+       /**
+          @todo deztructor: there is no check for option type yet
+        */
+       void setOptions(ParamsMapConst_t &options) {
+               for (ParamsMapConstIterator_t p = options.constBegin(); p != options.constEnd(); ++p) {
+                       settings_.setValue(p.key(), p.value());
+               }
+       }
+
+       ParamsMap_t getOptions() const {
+               ParamsMap_t options;
+               QStringList keys = settings_.allKeys();
+               for (QStringList::const_iterator p = keys.begin(); p != keys.end(); ++p) {
+                       options[*p] = settings_.value(*p).toString();
+               }
+               return options;
        }
 
 private:
        }
 
 private:
index 94c2465..b5d6e9d 100644 (file)
@@ -39,6 +39,7 @@ void TorrentSession::loadState()
                qDebug() << "adding " << info.path;
                addTorrent_(info.path, info.download_path, ParamsMap_t(), true);
        }
                qDebug() << "adding " << info.path;
                addTorrent_(info.path, info.download_path, ParamsMap_t(), true);
        }
+       btSession_.listen_on(settings_->getListenPorts());
 }
 
 void TorrentSession::on_alert()
 }
 
 void TorrentSession::on_alert()
@@ -190,5 +191,15 @@ void TorrentSession::removeTorrent(const QString &hash)
        db_->removeTorrent(hash);
 }
 
        db_->removeTorrent(hash);
 }
 
+void TorrentSession::setOptions(qtrapids::ParamsMap_t options)
+{
+       settings_->setOptions(options);
+}
+
+qtrapids::ParamsMap_t TorrentSession::getOptions()
+{
+       return settings_->getOptions();
+}
+
 
 } // namespace qtrapids
 
 } // namespace qtrapids
index 1baffac..4f56050 100644 (file)
@@ -16,6 +16,8 @@
 #include <libtorrent/alert_types.hpp>
 #include <libtorrent/error_code.hpp>
 
 #include <libtorrent/alert_types.hpp>
 #include <libtorrent/error_code.hpp>
 
+#include <utility>
+
 class QSettings;
 
 namespace qtrapids
 class QSettings;
 
 namespace qtrapids
@@ -35,6 +37,7 @@ typedef libtorrent::libtorrent_exception torrent_exception_t;
 
 typedef QSharedPointer<TorrentHandle> TorrentHandlePtr;
 typedef QHash<QString, TorrentHandlePtr > torrents_t;
 
 typedef QSharedPointer<TorrentHandle> TorrentHandlePtr;
 typedef QHash<QString, TorrentHandlePtr > torrents_t;
+typedef std::pair<int, int> ports_range_t;
 
 class ServerDb;
 class ServerSettings;
 
 class ServerDb;
 class ServerSettings;
@@ -55,6 +58,8 @@ public slots:
        void addTorrent(const QString &path, const QString &save_path
                        , qtrapids::ParamsMap_t other_params);
        void removeTorrent(const QString &hash);
        void addTorrent(const QString &path, const QString &save_path
                        , qtrapids::ParamsMap_t other_params);
        void removeTorrent(const QString &hash);
+       void setOptions(qtrapids::ParamsMap_t options);
+       qtrapids::ParamsMap_t getOptions();
 
 signals:
        void alert(qtrapids::TorrentState info, qtrapids::ParamsMap_t other_info);
 
 signals:
        void alert(qtrapids::TorrentState info, qtrapids::ParamsMap_t other_info);