-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmainwindow.cpp
179 lines (156 loc) · 4.98 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "copythread.h"
#include "listview.h"
#include <QtGui/QFileDialog>
#include <QtGui/QDesktopServices>
#include <QtGui/qmenu.h>
#include <QtGui/QMessageBox>
#include <QApplication>
QtMsgHandler oldMsgHandler = 0;
void LogMessageOutput(QtMsgType type, const char *msg)
{
QString result;
switch (type) {
case QtDebugMsg:
result = msg;
break;
// case QtInfoMsg:
// result = QString::fromPrintf("Info: %s", msg);
// break;
case QtWarningMsg:
result = QString::fromPrintf("Warning: %s", msg);
break;
case QtCriticalMsg:
result = QString::fromPrintf("Critical: %s", msg);
break;
case QtFatalMsg:
result = QString::fromPrintf("Fatal: %s", msg);
break;
}
MainWindow::log(result);
oldMsgHandler(type, msg);
//if(type == QtFatalMsg)
// abort();
}
QBasicMutex MainWindow::mutex;
MainWindow *MainWindow::instance = 0;
MainWindow::MainWindow(QWidget *parent)
: super(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QString gradlePath = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
gradlePath += QLatin1Literal("/.gradle/caches/modules-2/files-2.1");
ui->addressEdit->setText( QDir::toNativeSeparators(gradlePath) );
QString androidPath = QString::fromLocal8Bit(qgetenv("ANDROID_HOME")).trimmed();
if ( androidPath.isEmpty() ) {
QMessageBox::warning(this, QLL("Missing SDK"), QLL(
"Your ANDROID_HOME environment-variable is not set or empty!"
));
} else {
androidPath += QLatin1String("/extras/m2repository");
ui->targetEdit->setText( QDir::toNativeSeparators(androidPath) );
}
// Adds Drop-down menu to the start-button
QMenu *menu = new QMenu();
menu->addAction("Generate Missing Jar List", this, SLOT(generateDownloadList()));
ui->copyButton->setMenu(menu);
QMutexLocker locker(&mutex);
if (instance == Q_NULLPTR) {
instance = this;
}
// Any log output will wait until this returns
oldMsgHandler = qInstallMsgHandler(&LogMessageOutput);
}
MainWindow::~MainWindow()
{
QMutexLocker locker(&mutex);
delete ui;
if (instance == this) {
instance = 0;
}
}
void MainWindow::log(const QString &msg)
{
QMutexLocker locker(&mutex);
if (instance) {
QMetaObject::invokeMethod(instance->ui->logView, "appendPlainText"
, Qt::QueuedConnection, Q_ARG(QString, msg));
}
}
void MainWindow::showList(const QStringList &remoteLinks, const QStringList &localFiles)
{
ListView *lv = new ListView();
lv->setList(remoteLinks, localFiles);
CopyThread *thread = qobject_cast<CopyThread *>(sender());
if (thread) {
lv->setMavenFolder(thread->target());
}
lv->showNormal();
}
void MainWindow::showListIfAny(const QStringList &remoteLinks, const QStringList &localFiles)
{
if (remoteLinks.isEmpty() && localFiles.isEmpty()) {
return;
}
showList(remoteLinks, localFiles);
}
void MainWindow::on_browseButton_clicked()
{
QString path = QFileDialog::getExistingDirectory(this);
ui->addressEdit->setText(path);
}
void MainWindow::on_selectTargetButton_clicked()
{
QString path = QFileDialog::getExistingDirectory(this);
ui->targetEdit->setText(path);
}
void MainWindow::postCopyOperation()
{
startOperation(CopyThread::GetLinkList, true);
}
bool MainWindow::ensureSource(QDir *source)
{
*source = QDir(ui->addressEdit->text());
if (source->exists()) {
return true;
}
QApplication::beep();
ui->addressEdit->setFocus();
ui->addressEdit->selectAll();
return false;
}
CopyThread *MainWindow::ensureThread(CopyThread::OperationType ot)
{
CopyThread *thread = 0;
QDir source;
if ( ot == CopyThread::GetLinkList || ensureSource(&source) ) {
QString target = ui->targetEdit->text();
thread = new CopyThread();
connect(thread, &QThread::finished, thread, &QObject::deleteLater);
connect(thread, &CopyThread::statusChanged, this->ui->statusView, &QLabel::setText, Qt::QueuedConnection);
connect(thread, &CopyThread::domainChanged, this->ui->statusView, &QLabel::setText, Qt::QueuedConnection);
thread->prepare(source, target, ui->testRun->isChecked());
}
return thread;
}
void MainWindow::startOperation(CopyThread::OperationType ot, bool silent)
{
CopyThread *t = ensureThread(ot);
if (t) {
t->setOperation(ot);
if (ot == CopyThread::GetLinkList) {
if ( ! silent) {
connect(t, &CopyThread::listReady, this, &MainWindow::showList);
} else {
connect(t, &CopyThread::listReady, this, &MainWindow::showListIfAny);
}
} else if (ot == CopyThread::CopyLibraries
&& ! ui->testRun->isChecked()
) {
connect(t, &CopyThread::finished, this, &MainWindow::postCopyOperation);
}
t->start();
}
}