-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
181 lines (162 loc) · 7.46 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include "mainwindow.h"
#include <attica/provider.h>
#include <attica/providermanager.h>
#include <attica/person.h>
#include <attica/itemjob.h>
#include <QTextEdit>
#include <QHBoxLayout>
#include <QCommandLinkButton>
#include "categorybutton.h"
#include "softwareitem.h"
#include <attica/category.h>
#include <attica/content.h>
#include <QListWidget>
#include <QDebug>
#include <attica/downloaditem.h>
#include <QWebView>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
this->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding);
this->setMinimumWidth(600);
QHBoxLayout *hbox = new QHBoxLayout;
m_categories = new QVBoxLayout;
hbox->addLayout(m_categories);
m_SoftwareList = new QListWidget;
hbox->addWidget(m_SoftwareList);
QWidget *center = new QWidget;
center->setLayout(hbox);
this->setCentralWidget(center);
QCommandLinkButton *test = new QCommandLinkButton(QString::fromLatin1("buton de test"));
//categories->addWidget(test);
connect(m_SoftwareList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), SLOT(softwareSelected(QListWidgetItem*)));
connect(&m_manager, SIGNAL(defaultProvidersLoaded()), SLOT(providersChanged()));
// tell it to get the default Providers
m_manager.addProviderFromXml(QString::fromLatin1("<provider>"
"<id>opendesktop</id>"
"<location>http://api.opendesktop.org/v1/</location>"
"<name>openDesktop.org</name>"
"<icon></icon>"
"<termsofuse>https://opendesktop.org/terms/</termsofuse>"
"<register>https://opendesktop.org/usermanager/new.php</register>"
"<services>"
" <person ocsversion=\"1.3\" />"
" <friend ocsversion=\"1.3\" />"
" <message ocsversion=\"1.3\" />"
" <activity ocsversion=\"1.3\" />"
" <content ocsversion=\"1.3\" />"
" <fan ocsversion=\"1.3\" />"
" <knowledgebase ocsversion=\"1.3\" />"
" <event ocsversion=\"1.3\" />"
"</services>"
"</provider>"));
m_manager.addProviderFromXml(QString::fromLatin1("<provider>"
"<id>opendesktop</id>"
"<location>http://ec2-46-51-134-160.eu-west-1.compute.amazonaws.com/ocs/</location>"
"<name>Kde Windows Test</name>"
"<icon></icon>"
"<termsofuse>https://opendesktop.org/terms/</termsofuse>"
"<register>https://opendesktop.org/usermanager/new.php</register>"
"<services>"
" <person ocsversion=\"1.3\" />"
" <friend ocsversion=\"1.3\" />"
" <message ocsversion=\"1.3\" />"
" <activity ocsversion=\"1.3\" />"
" <content ocsversion=\"1.3\" />"
" <fan ocsversion=\"1.3\" />"
" <knowledgebase ocsversion=\"1.3\" />"
" <event ocsversion=\"1.3\" />"
"</services>"
"</provider>"));
}
void MainWindow::providersChanged()
{
qDebug("provider has changed");
if (!m_manager.providers().isEmpty()) {
qDebug("provider list is not empty");
// m_provider = m_manager.providerByUrl(QUrl(QString::fromAscii("http://ec2-46-51-134-160.eu-west-1.compute.amazonaws.com/ocs/")));
m_provider = m_manager.providerByUrl(QUrl(QString::fromAscii("http://api.opendesktop.org/v1/")));
if (!m_provider.isValid()) {
qDebug("provider is not valid");
return;
}
Attica::ListJob<Attica::Category>* job = m_provider.requestCategories();
connect(job, SIGNAL(finished(Attica::BaseJob*)), SLOT(onContentRecieved(Attica::BaseJob*)));
job->start();
}
}
void MainWindow::onContentRecieved(Attica::BaseJob *job)
{
qDebug("Job finished");
Attica::ListJob<Attica::Category> *personJob = static_cast< Attica::ListJob<Attica::Category> * >( job );
if (personJob->metadata().error() == Attica::Metadata::NoError)
{
int i = 0;
Attica::Category::List l(personJob->itemList());
for (QList <Attica::Category>::iterator it = l.begin(); it!=l.end(); ++ it)
{
Attica::Category *cat = new Attica::Category(*it);
CategoryButton *category_button = new CategoryButton(this,cat);
category_button->category=cat;
connect(category_button,SIGNAL(clicked()),this,SLOT(category_selected()));
m_categories->addWidget(category_button);
if (i>10)
break;
++i;
}
}
else
qDebug("job didn't go well");
}
void MainWindow::category_selected()
{
CategoryButton *test =static_cast < CategoryButton *>(QObject::sender());
QList <Attica::Category> list;
list.append(*(test->category));
Attica::ListJob<Attica::Content>* job = m_provider.searchContents(list);
m_SoftwareList->clear();
connect(job, SIGNAL(finished(Attica::BaseJob*)), SLOT(onContentListRecieved(Attica::BaseJob*)));
job->start();
}
void MainWindow::onContentListRecieved(Attica::BaseJob *job)
{
Attica::ListJob<Attica::Content> *ContentListJob = static_cast< Attica::ListJob<Attica::Content> * >( job );
if (ContentListJob->metadata().error() == Attica::Metadata::NoError)
{
QString clist;
Attica::Content::List l(ContentListJob->itemList());
for (Attica::Content::List::iterator it = l.begin(); it!=l.end(); ++ it)
{
Attica::Content *temp_content = new Attica::Content(static_cast < Attica::Content> (*it));
m_SoftwareList->addItem( new SoftwareItem(temp_content ));
}
}
}
void MainWindow::softwareSelected(QListWidgetItem* item)
{
SoftwareItem *sitem = static_cast < SoftwareItem *> (item);
qDebug("reached here");
Attica::Content *content = sitem->getContent();
qDebug("got content");
if (content == NULL)
qDebug("content is NULL");
else
{
qDebug()<<"should now install software named:"<<content->name()<<endl;
qDebug()<<"software has "<<content->downloadUrlDescriptions().count()<<" instalation methods";
int n= content->downloadUrlDescriptions().count();
for (int i = 0; i < n ; ++i)
{
Attica::DownloadDescription down = content->downloadUrlDescription(i+1);
qDebug()<<"Download "<<down.name();
qDebug()<<"type is "<<down.type();
qDebug()<<" and a package "<<down.packageName();
qDebug()<<" from repo "<<down.repository();
qDebug()<<" a link "<<down.link();
qDebug()<<endl;
}
}
QWebView *test = new QWebView;
test->setUrl(content->detailpage());
test->show();
}