-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud-tools.cpp
147 lines (137 loc) · 4.65 KB
/
cloud-tools.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
#include "cloud.h"
#include "ui_cloud.h"
#include "QSettings"
#include "QDebug"
#include "QMenu"
#include <QTimer>
#include <QHttp>
#include <QBuffer>
#include <QList>
#include <QFile>
#include <QtGui>
#include "addserver.h"
void Cloud::appExit()
{
QProcess* p = new QProcess();
p->start(setGlobal->value("Global/CloseApp").toString(),
QStringList(QString(
QCoreApplication::applicationDirPath() + "/" + setGlobal->value("Global/uTorrentExe").toString()
).replace("/", "\\")));
p = new QProcess();
p->start(setGlobal->value("Global/CloseApp").toString(),
QStringList(QString(
QCoreApplication::applicationDirPath() + "/" + setGlobal->value("Global/uTorrentExe").toString()
).replace("/", "\\")));
p = new QProcess();
QStringList sl;
sl << "/F" << QString(QCoreApplication::applicationDirPath() + "/" + setGlobal->value("Global/Webserver").toString()).replace("/", "\\");
p->start(setGlobal->value("Global/CloseApp").toString(), sl);
close();
}
void Cloud::show_utorrent()
{
torrent->showApp();
}
void Cloud::readIni(QString ini)
{
QString ret;
qDebug() << "begin readIni";
QSettings* set = new QSettings(setGlobal->value("Global/Database").toString() + "/" + ini, QSettings::IniFormat);
qDebug() << "read";
for (int i = 1; i <= 255; i++)
{
QString item = QString("item%1").arg(i);
if (!set->value(item + "/name").toString().isEmpty())
{
game g;
g.name = set->value(item + "/name").toString();
g.folder = set->value(item + "/folder").toString();
ret = g.hash = set->value("global/hash").toString();
g.location = set->value("global/folder").toString();
g.icon = set->value(item + "/icon").toString();
g.url = set->value(item + "/url").toString();
int i = 1;
while (!set->value(item + QString("/file%1").arg(i)).toString().isEmpty())
{
g.files << set->value(item + QString("/file%1").arg(i)).toString();
i++;
}
qDebug() << "added one game";
if (!g.name.isEmpty())
games << g;
}
}
qDebug() << "end readIni";
hashes << ret;
}
void Cloud::updateContent()
{
TRACE(5, "");
QDir dir(setGlobal->value("Global/Database").toString());
QStringList listgames = dir.entryList(
QStringList("*." + setGlobal->value("Global/TorrentDescriptionExt").toString()));
foreach(QString game,listgames)
{
TRACE(5, "will read" << game);
readIni(game);
}
ui->list->setContextMenuPolicy(Qt::CustomContextMenu);
for (int i = 0; i < games.size(); i++)
{
{
qDebug() << "will add";
QTreeWidgetItem* lwitem = new QTreeWidgetItem();
lwitem->setText(0, games.at(i).name);
QFont f = lwitem->font(0);
f.setBold(true);
f.setPixelSize(14);
lwitem->setFont(0, f);
lwitem->setIcon(0, QIcon(QString(setGlobal->value("Global/Database").toString() + "/%1").arg(games.at(i).icon)));
lwitem->setData(0, Qt::UserRole, i);
lwitem->setData(0, Qt::UserRole + 1, 1);
ui->list->addTopLevelItem(lwitem);
items[i] = lwitem;
}
}
TRACE(5, "");
}
void Cloud::on_list_customContextMenuRequested(QPoint pos)
{
QTreeWidgetItem* qtwi = ui->list->itemAt(pos);
if (qtwi)
{
qDebug() << "custom" << qtwi->text(0);
if (qtwi->data(0, Qt::UserRole + 1).toInt() == 1)
{
currentItem = qtwi->data(0, Qt::UserRole).toInt();
QMenu menu;
menu.addSeparator();
if (setGlobal->value("Global/uTorrent") == 1)
{
menu.addAction(QIcon(), tr("&Download and install"), this, SLOT(dl_start()));
menu.addAction(QIcon(), tr("Download &only"), this, SLOT(dl_start_low()));
menu.addAction(QIcon(), tr("&Stop"), this, SLOT(dl_stop()));
menu.addAction(QIcon(), tr("&Reinstall"), this, SLOT(dl_reinstall()));
}
menu.addAction(QIcon(), tr("&Reconfigure"), this, SLOT(dl_reconfigure()));
if (setGlobal->value("Global/isAdmin").toInt() == 1)
{
menu.addAction(QIcon(), tr("Download and install for ALL"), this, SLOT(dl_start_all()));
menu.addAction(QIcon(), tr("Download only for ALL"), this, SLOT(dl_start_low_all()));
menu.addAction(QIcon(), tr("Stop for ALL"), this, SLOT(dl_stop_all()));
}
menu.exec(QCursor::pos());
}
}
}
void Cloud::newIp()
{
AddServer w(setGlobal);
int result = w.exec();
if (result == QDialog::Accepted)
{
QStringList sl = setGlobal->value("Global/MasterServers").toStringList();
sl << w.getIp();
setGlobal->setValue("Global/MasterServers", sl);
}
}