26a7760ff5ace8d92d1840248a91ec5cb83c989c
[qtrapids] / src / qml-client / MainPageHandler.cpp
1 /*
2     <one line to give the program's name and a brief idea of what it does.>
3     Copyright (C) 2012  Ixonos Plc
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <QtCore/QString>
21 #include <QtCore/QDebug>
22 #include <QFileDialog>
23 #include <meegotouch/mwindow.h>
24
25 #include "MainPageHandler.h"
26
27
28 namespace qtrapids
29 {
30
31 MainPageHandler::MainPageHandler(QObject *parent) :
32     QObject(parent)
33 {
34 }
35
36 MainPageHandler::~MainPageHandler()
37 {
38 }
39
40 void MainPageHandler::fileSelectorOpen()
41 {
42     qDebug() << Q_FUNC_INFO;
43     QWidget* widget = qobject_cast<QWidget*>(MApplication::activeWindow());
44     QString filename = QFileDialog::getOpenFileName(widget, tr("Open torrent file"), QString(), tr("Torrent files (*.torrent)") );
45     on_torrentFileSelected(filename);
46 }
47
48
49 void MainPageHandler::on_torrentFileSelected(const QString& file)
50 {
51     qDebug() << Q_FUNC_INFO << " file selected: " << file;
52
53     // Torrent filename empty, do nothing.
54     if (file == "") {
55         return;
56     }
57
58     // Otherwise add torrent
59     // For params, see: http://www.rasterbar.com/products/libtorrent/manual.html#add-torrent
60     // save_path is the only mandatory parameter, rest are optional.
61     //addParams.storage_mode = libtorrent::storage_mode_allocate;
62     try {
63         // TODO: Enable this once server_ is in place
64 //         server_.addTorrent(file,
65 //                            settings_.value("download/directory").toString(),
66 //                            ParamsMap_t());
67     } catch (...) {
68         qDebug() << Q_FUNC_INFO << "Exception adding torrent";
69     }
70 }
71
72 } //namespace qtrapids