9d992b8acf6fe74d4c50f5f055d4238dcefdbbd3
[qtrapids] / src / client / main.cpp
1 /***************************************************************************
2  *   Copyright (C) 2010 by Ixonos Plc   *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; version 2 of the License.               *
7  *                                                                         *
8  *   This program is distributed in the hope that it will be useful,       *
9  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
10  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
11  *   GNU General Public License for more details.                          *
12  *                                                                         *
13  *   You should have received a copy of the GNU General Public License     *
14  *   along with this program; if not, write to the                         *
15  *   Free Software Foundation, Inc.,                                       *
16  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
17  ***************************************************************************/
18 #include <QApplication>
19 #include <QtDeclarative>
20 #include <QDeclarativeContext>
21 #include <QTest>
22 #include <QDebug>
23 //#include <QDesktopWidget>
24 //#include "DownloadView.h"
25 #include <QtDeclarative/qdeclarative.h>
26 #include "models/QDeclarativeDownloadListModel.h"
27
28 #include "MainWindow.h"
29 #include "../include/qtrapids/dbus.hpp"
30
31 using qtrapids::MainWindow;
32
33 int main(int argc, char *argv[])
34 {
35
36
37
38     QCoreApplication::setOrganizationName("Ixonos");
39     QCoreApplication::setOrganizationDomain("ixonos.com");
40     QCoreApplication::setApplicationName("QtRapids");
41
42     // Q_INIT_RESOURCE(application);
43     QApplication app(argc, argv);
44     //MainWindow mainWindow;
45     app.setProperty("NoMStyle", true);
46     
47     // Register our types:
48     qmlRegisterType<qtrapids::QDeclarativeDownloadListModel>("QtRapids", 1, 0, "DownloadListModel");
49
50     QDir::setCurrent(app.applicationDirPath());
51
52     QDeclarativeView window;
53     //QDeclarativeEngine engine;
54     qtrapids::QDeclarativeDownloadListModel downloadModel;
55     QDeclarativeContext *context = window.rootContext();
56     context->setContextProperty("downloadModel", &downloadModel);
57     window.setSource(QUrl("qrc:/main.qml"));
58
59     window.showFullScreen();
60 //    window.show();
61
62
63     /* TODO: Enable this once we have the views up & running
64     QDBusConnection dbus = QDBusConnection::sessionBus();
65     dbus.registerObject("/qtrapids_gui", &mainWindow);
66     dbus.registerService("com.ixonos.qtrapids_gui");
67
68     mainWindow.connectToServer();
69     mainWindow.RestoreSettings();
70
71     // mainWindow->setGeometry(QApplication::desktop()->screenGeometry());
72
73     mainWindow.show();
74     */
75     /*
76     DownloadView* dlw = new DownloadView(NULL);
77       //qtrapids * mw = new qtrapids();
78     dlw->show();
79     DownloadViewItem* dlwItem = new DownloadViewItem(QStringList() << "Name"
80                 << "Size" << "Status"
81                 << "Progress" << "DL speed"
82                 << "UL speed" << "Seeds/Leechers"
83                 << "ratio");
84     DownloadViewItem* dlwItem2 = new DownloadViewItem(QStringList() << "Name"
85                 << "1000" << "Downloading"
86                 << "23%" << "11"
87                 << "0.1" << "0/2"
88                 << "1.10");
89     //dlwItem->insertChild(0, new DownloadViewItem(QStringList() << "Name"));
90     dlw->insertTopLevelItem(0,dlwItem);
91     dlw->insertTopLevelItem(1,dlwItem2);
92
93     for (unsigned i = 0; i < 10; ++i)
94     {
95         DownloadViewItem *editItem = dynamic_cast<DownloadViewItem*>
96                         (dlw->itemAt(QPoint(0,0)));
97         editItem->setData ( 8, Qt::DisplayRole, QVariant("EDITED" + QString::number(i, 'g', 2)));
98         QTest::qSleep(2000);
99     }
100     */
101
102     qtrapids::TorrentState editItem;
103     for (unsigned i = 0; i < 10; ++i)
104     {
105         editItem.hash = QString("asdfasdfasdfasdfasfsd-") + QString::number(i);
106         editItem.name = QString("Lassi-") + QString::number(i);
107         editItem.action = qtrapids::TorrentState::action_add;
108         editItem.state = 0;
109         editItem.progress = 10+i;
110         editItem.down_rate = 10+i;
111         editItem.up_rate = 10+i;
112         editItem.seeds = 10+i;
113         editItem.leeches = 10+i;
114         editItem.ratio = 10+i;
115         editItem.total_size = 100000+i;
116         editItem.total_done = 10000+i;
117         downloadModel.updateItem(editItem, qtrapids::ParamsMap_t());
118     }
119
120     return app.exec();
121 }