-
Notifications
You must be signed in to change notification settings - Fork 17
/
mainwindow.cpp
718 lines (617 loc) · 25.6 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
///////////////////////////////////////////////////////////////////////////////
// //
// This file is part of qt-pods. //
// Copyright (C) 2015 Jacob Dawid, jacob@omg-it.works //
// //
// qt-pods is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// qt-pods is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with qt-pods. If not, see <http://www.gnu.org/licenses/>. //
// //
///////////////////////////////////////////////////////////////////////////////
// Own includes
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "pod.h"
#include "poddialog.h"
#include "sourcesdialog.h"
// Qt includes
#include <QFileDialog>
#include <QSettings>
#include <QStandardPaths>
#include <QMessageBox>
#include <QDesktopServices>
#include <QDebug>
#ifdef Q_OS_UNIX
#include <unistd.h>
#endif
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow) {
setObjectName("MainWindow");
// Redirect all messages from console
setupStdOutRedirect();
// Application settings object
_settings = new QSettings("qt-pods", "qt-pods");
// Create pod manager and move it to a background thread
_workerThread = new QThread();
_podManager = new PodManager();
_podManager->moveToThread(_workerThread);
_workerThread->start();
connect(_podManager, SIGNAL(installPodsFinished(QString, QList<Pod>, bool)),
this, SLOT(installPodsFinished(QString,QList<Pod>,bool)));
connect(_podManager, SIGNAL(removePodsFinished(QString, QStringList, bool)),
this, SLOT(removePodsFinished(QString, QStringList,bool)));
connect(_podManager, SIGNAL(updatePodsFinished(QString, QStringList, bool)),
this, SLOT(updatePodsFinished(QString, QStringList, bool)));
connect(_podManager, SIGNAL(listInstalledPodsFinished(QString, QList<Pod>)),
this, SLOT(listInstalledPodsFinished(QString,QList<Pod>)));
connect(_podManager, SIGNAL(listAvailablePodsFinished(QStringList, QList<Pod>)),
this, SLOT(listAvailablePodsFinished(QStringList,QList<Pod>)));
connect(_podManager, SIGNAL(createProjectFinished(QString,bool)),
this, SLOT(createProjectFinished(QString,bool)));
// UI setup
ui->setupUi(this);
ui->tabWidget->setTabToolTip(ui->tabWidget->indexOf(ui->tabLocalPods),
tr("Manage locally installed pods."));
ui->tabWidget->setTabWhatsThis(ui->tabWidget->indexOf(ui->tabLocalPods),
tr("Manage locally installed pods."));
ui->tabWidget->setTabToolTip(ui->tabWidget->indexOf(ui->tabAvailablePods),
tr("View and install from a list of available pods."));
ui->tabWidget->setTabWhatsThis(ui->tabWidget->indexOf(ui->tabAvailablePods),
tr("View and install from a list of available pods."));
ui->tabWidget->setTabToolTip(ui->tabWidget->indexOf(ui->tabDevelopmentTools),
tr("Pod developers tools."));
ui->tabWidget->setTabWhatsThis(ui->tabWidget->indexOf(ui->tabDevelopmentTools),
tr("Pod developers tools."));
ui->tabWidget->setTabToolTip(ui->tabWidget->indexOf(ui->tabDiagnostic),
tr("Debug information for developers."));
ui->tabWidget->setTabWhatsThis(ui->tabWidget->indexOf(ui->tabDiagnostic),
tr("Debug information for developers."));
_localPods = new PodsModel();
_remotePods = new PodsModel();
_localPodsProxyModel = new QSortFilterProxyModel();
_localPodsProxyModel->setSourceModel(_localPods);
_localPodsProxyModel->setFilterKeyColumn(-1);
_remotePodsProxyModel = new QSortFilterProxyModel();
_remotePodsProxyModel->setSourceModel(_remotePods);
_remotePodsProxyModel->setFilterKeyColumn(-1);
ui->tableViewLocal->setModel(_localPodsProxyModel);
ui->tableViewRemote->setModel(_remotePodsProxyModel);
_systemTrayIcon.setIcon(QIcon(":/icons/icons/system-upgrade.svg"));
_systemTrayIcon.setToolTip("Qt Pods");
_systemTrayIcon.show();
_availablePodsSpinnerWidget = new WaitingSpinnerWidget(ui->tabAvailablePods);
_localPodsSpinnerWidget = new WaitingSpinnerWidget(ui->tabLocalPods);
_developmentToolsSpinnerWidget = new WaitingSpinnerWidget(ui->tabDevelopmentTools);
updateBuildInfo();
loadSettings();
#ifndef QT_DEBUG
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabDiagnostic));
#endif
}
MainWindow::~MainWindow() {
delete ui;
}
void MainWindow::stdOutActivated(int fileDescriptor) {
char readBuffer[1024];
int numberOfBytesRead = ::read(fileDescriptor, readBuffer, sizeof(readBuffer) - 1);
if(numberOfBytesRead > 0) {
// Terminate buffer - just in case.
readBuffer[numberOfBytesRead] = (char)0;
#ifdef QT_DEBUG
ui->plainTextEditDiagnostic->appendPlainText(readBuffer);
#else
statusBar()->showMessage(readBuffer);
#endif
}
}
void MainWindow::updateBuildInfo() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[updateBuildInfo]";
#endif
QString buildString = QString("%1-%2 (built on %3 at %4)")
.arg(GIT_VERSION)
#ifdef QT_DEBUG
.arg("debug")
#else
.arg("release")
#endif
.arg(__DATE__)
.arg(__TIME__);
ui->lineEditBuild->setText(buildString);
_buildString = buildString;
}
void MainWindow::setupStdOutRedirect() {
#ifdef Q_OS_UNIX
// Redirect our own stdout/stderr.
int pipeDescriptors[2];
if(::pipe(pipeDescriptors) == 0) {
::dup2(pipeDescriptors[1], STDOUT_FILENO);
::dup2(pipeDescriptors[1], STDERR_FILENO);
_stdOutSocketNotifier = new QSocketNotifier(pipeDescriptors[0], QSocketNotifier::Read, this);
connect(_stdOutSocketNotifier, SIGNAL(activated(int)),
this, SLOT(stdOutActivated(int)));
}
#endif
}
void MainWindow::on_pushButtonAddRepository_clicked() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_pushButtonAddRepository_clicked]";
#endif
QString directory = QFileDialog::getExistingDirectory(this, tr("Add git repository"));
if(!directory.isEmpty()) {
if(!_podManager->isGitRepository(directory)) {
QMessageBox::warning(this,
tr("Invalid repository"),
tr("The directory you supplied does not appear to be the root of a valid git repository."));
return;
}
if(ui->comboBoxCurrentRepository->findText(directory) == -1) {
ui->comboBoxCurrentRepository->addItem(directory);
}
ui->comboBoxCurrentRepository->setCurrentText(directory);
saveSettings();
refreshLocalPods();
}
}
void MainWindow::on_pushButtonRemoveRepository_clicked() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_pushButtonRemoveRepository_clicked]";
#endif
int confirmationResult = QMessageBox::warning(this,
tr("Confirm removal"),
tr("Are you sure you want to remove the repository \"%1\"?")
.arg(ui->comboBoxCurrentRepository->currentText()), QMessageBox::No, QMessageBox::Yes);
if(confirmationResult == QMessageBox::Yes) {
ui->comboBoxCurrentRepository->removeItem(ui->comboBoxCurrentRepository->currentIndex());
saveSettings();
}
}
void MainWindow::on_pushButtonNewProject_clicked() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_pushButtonNewRepository_clicked]";
#endif
QString directory = QFileDialog::getExistingDirectory(this, tr("Choose a folder to create the project in"));
if(!directory.isEmpty()) {
metaObject()->invokeMethod(_podManager, "createProject",
Q_ARG(QString, directory));
}
}
void MainWindow::on_comboBoxCurrentRepository_currentTextChanged(QString text) {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_comboBoxCurrentRepository_currentTextChanged]";
#endif
setWindowTitle(QString("Qt Pods - %1 - %2").arg(text).arg(_buildString));
refreshLocalPods();
}
void MainWindow::on_tabWidget_currentChanged(int index) {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_tabWidgetPods_currentChanged]";
#endif
switch (index) {
case 0:
refreshLocalPods();
break;
case 1:
refreshAvailablePods();
default:
break;
}
}
void MainWindow::on_lineEditSearchLocal_textChanged(QString text) {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_lineEditSearchLocal_textChanged]";
#endif
_localPodsProxyModel->setFilterWildcard(text);
}
void MainWindow::on_lineEditSearchRemote_textChanged(QString text) {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_lineEditSearchRemote_textChanged]";
#endif
_remotePodsProxyModel->setFilterWildcard(text);
}
void MainWindow::on_pushButtonRemoveLocalPods_clicked() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_pushButtonRemoveLocalPods_clicked]";
#endif
QItemSelection itemSelection = ui->tableViewLocal->selectionModel()->selection();
QModelIndexList selectedModelIndices = _localPodsProxyModel->mapSelectionToSource(itemSelection).indexes();
QModelIndexList modelIndices;
foreach(QModelIndex i, selectedModelIndices) {
if(i.column() == 0) {
modelIndices.append(i);
}
}
if(modelIndices.count() == 0) {
return;
}
int confirmationResult;
if(modelIndices.count() == 1) {
confirmationResult = QMessageBox::warning(this,
tr("Confirm removal"),
tr("Are you sure you want to remove \"%1\" from the repository?")
.arg(modelIndices.at(0).data().toString()), QMessageBox::No, QMessageBox::Yes);
} else {
confirmationResult = QMessageBox::warning(this,
tr("Confirm removal"),
tr("Are you sure you want to remove %1 pods from the repository?")
.arg(modelIndices.count()), QMessageBox::No, QMessageBox::Yes);
}
if(confirmationResult == QMessageBox::Yes) {
_localPodsSpinnerWidget->start();
QStringList podNames;
foreach(QModelIndex modelIndex, modelIndices) {
podNames.append(_localPods->pod(modelIndex).name);
}
metaObject()->invokeMethod(_podManager, "removePods",
Q_ARG(QString, ui->comboBoxCurrentRepository->currentText()),
Q_ARG(QStringList, podNames));
}
}
void MainWindow::on_pushButtonUpdateLocalPods_clicked() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_pushButtonUpdateLocalPods_clicked]";
#endif
QItemSelection itemSelection = ui->tableViewLocal->selectionModel()->selection();
QModelIndexList selectedModelIndices = _localPodsProxyModel->mapSelectionToSource(itemSelection).indexes();
QModelIndexList modelIndices;
foreach(QModelIndex i, selectedModelIndices) {
if(i.column() == 0) {
modelIndices.append(i);
}
}
if(modelIndices.count() == 0) {
return;
}
int confirmationResult;
if(modelIndices.count() == 1) {
confirmationResult = QMessageBox::warning(this,
tr("Confirm update"),
tr("Are you sure you want to update \"%1\"?")
.arg(modelIndices.at(0).data().toString()),QMessageBox::No, QMessageBox::Yes);
} else {
confirmationResult = QMessageBox::warning(this,
tr("Confirm update"),
tr("Are you sure you want to update \"%1\" pods?")
.arg(modelIndices.count()), QMessageBox::No, QMessageBox::Yes);
}
if(confirmationResult == QMessageBox::Yes) {
_localPodsSpinnerWidget->start();
QStringList podNames;
foreach(QModelIndex modelIndex, modelIndices) {
podNames.append(_localPods->pod(modelIndex).name);
}
metaObject()->invokeMethod(_podManager, "updatePods",
Q_ARG(QString, ui->comboBoxCurrentRepository->currentText()),
Q_ARG(QStringList, podNames));
}
}
void MainWindow::on_pushButtonRefreshLocalPods_clicked() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_pushButtonRefreshLocalPods_clicked]";
#endif
ui->tableViewLocal->setEnabled(false);
ui->pushButtonRemoveLocalPods->setEnabled(false);
ui->pushButtonRefreshLocalPods->setEnabled(false);
refreshLocalPods();
ui->tableViewLocal->setEnabled(true);
ui->pushButtonRemoveLocalPods->setEnabled(true);
ui->pushButtonRefreshLocalPods->setEnabled(true);
}
void MainWindow::on_pushButtonManageSources_clicked() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_pushButtonManageSources_clicked]";
#endif
SourcesDialog sourcesDialog;
QStringList sources = _settings->value("sources").toStringList();
// At least add one source
if(sources.isEmpty()) {
sources << "http://qt-pods.org/pods.json";
}
sourcesDialog.setSources(sources);
if(sourcesDialog.exec() == QDialog::Accepted) {
_settings->setValue("sources", sourcesDialog.sources());
_settings->sync();
}
}
void MainWindow::on_pushButtonRefreshAvailablePods_clicked() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_pushButtonRefreshAvailablePods_clicked]";
#endif
ui->tableViewRemote->setEnabled(false);
ui->pushButtonInstallPods->setEnabled(false);
ui->pushButtonRefreshAvailablePods->setEnabled(false);
refreshAvailablePods();
ui->tableViewRemote->setEnabled(true);
ui->pushButtonInstallPods->setEnabled(true);
ui->pushButtonRefreshAvailablePods->setEnabled(true);
}
void MainWindow::on_pushButtonInstallPods_clicked() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_pushButtonInstallPods_clicked]";
#endif
_availablePodsSpinnerWidget->start();
_localPodsSpinnerWidget->start();
QItemSelection itemSelection = ui->tableViewRemote->selectionModel()->selection();
QModelIndexList selectedModelIndices =_remotePodsProxyModel->mapSelectionToSource(itemSelection).indexes();
QModelIndexList modelIndices;
foreach(QModelIndex i, selectedModelIndices) {
if(i.column() == 0) {
modelIndices.append(i);
}
}
QList<Pod> pods = _remotePods->pods(modelIndices);
metaObject()->invokeMethod(_podManager,
"installPods",
Q_ARG(QString, ui->comboBoxCurrentRepository->currentText()),
Q_ARG(QList<Pod>, pods));
}
void MainWindow::on_pushButtonInstallExternalPod_clicked() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_pushButtonInstallExternalPod_clicked]";
#endif
PodDialog podDialog;
if(podDialog.exec() == QDialog::Accepted) {
_availablePodsSpinnerWidget->start();
_localPodsSpinnerWidget->start();
QList<Pod> pods;
pods.append(podDialog.pod());
metaObject()->invokeMethod(_podManager,
"installPods",
Q_ARG(QString, ui->comboBoxCurrentRepository->currentText()),
Q_ARG(QList<Pod>, pods));
}
}
void MainWindow::on_pushButtonReportIssue_clicked() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_pushButtonReportIssue_clicked]";
#endif
QDesktopServices desktopServices;
desktopServices.openUrl(QUrl("https://github.com/cybercatalyst/qt-pods/issues"));
}
void MainWindow::on_pushButtonExportDiagnostics_clicked() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_pushButtonExportDiagnostics_clicked]";
#endif
QString fileName = QFileDialog::getSaveFileName(this, tr("Save diagnostics"), "diagnostics.txt", "*.txt");
if(!fileName.isEmpty()) {
QFile file(fileName);
file.open(QFile::ReadWrite);
if(file.isOpen()) {
file.write((ui->lineEditBuild->text() + "\n").toUtf8());
file.write(ui->plainTextEditDiagnostic->toPlainText().toUtf8());
file.waitForBytesWritten(30000);
file.close();
QMessageBox::information(this,
tr("Diagnostics written"),
tr("Diagnostics have been written to %1. Please attach this file when reporting issues. Thank you!")
.arg(file.fileName()));
} else {
QMessageBox::warning(this,
tr("Error writing to file"),
tr("Diagnostics could not be written. Reason: %1")
.arg(file.errorString()));
}
}
}
void MainWindow::on_tableViewLocal_doubleClicked(QModelIndex index) {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_tableViewLocal_doubleClicked]";
#endif
PodDialog podDialog;
podDialog.setPod(_localPods->pod(index));
podDialog.setEditable(false);
podDialog.exec();
}
void MainWindow::on_tableViewRemote_doubleClicked(QModelIndex index) {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_tableViewRemote_doubleClicked]";
#endif
PodDialog podDialog;
podDialog.setPod(_remotePods->pod(index));
podDialog.setEditable(false);
podDialog.exec();
}
void MainWindow::on_toolButtonChooseDevelopmentPodRoot_clicked() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_toolButtonChooseDevelopmentPodRoot_clicked]";
#endif
QString podRoot = QFileDialog::getExistingDirectory(this, tr("Choose pod root directory"));
if(!podRoot.isEmpty()) {
ui->lineEditDevelopmentPodRoot->setText(podRoot);
}
}
void MainWindow::on_lineEditDevelopmentPodRoot_textChanged(QString text) {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_lineEditDevelopmentPodRoot_textChanged]";
#endif
QFileInfo fileInfo(text);
if(fileInfo.exists() && fileInfo.isDir()) {
ui->lineEditDevelopmentPodRoot->setStyleSheet("color: green;");
ui->pushButtonDevelopmentPodInstall->setEnabled(true);
//ui->pushButtonDevelopmentPodSanityCheck->setEnabled(true);
} else {
ui->lineEditDevelopmentPodRoot->setStyleSheet("color: red;");
ui->pushButtonDevelopmentPodInstall->setEnabled(false);
ui->pushButtonDevelopmentPodSanityCheck->setEnabled(false);
}
}
void MainWindow::on_pushButtonDevelopmentPodSanityCheck_clicked() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_pushButtonDevelopmentPodSanityCheck_clicked]";
#endif
// TODO: Implement maybe in core.
}
void MainWindow::on_pushButtonDevelopmentPodInstall_clicked() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[on_pushButtonDevelopmentPodInstall_clicked]";
#endif
_availablePodsSpinnerWidget->start();
_localPodsSpinnerWidget->start();
_developmentToolsSpinnerWidget->start();
QList<Pod> pods;
QFileInfo fileInfo(ui->lineEditDevelopmentPodRoot->text());
if(fileInfo.exists() && fileInfo.isDir()) {
Pod pod;
pod.url = ui->lineEditDevelopmentPodRoot->text();
pod.description = tr("Development pod at %1").arg(fileInfo.absolutePath());
pod.name = fileInfo.fileName();
pods.append(pod);
metaObject()->invokeMethod(_podManager,
"installPods",
Q_ARG(QString, ui->comboBoxCurrentRepository->currentText()),
Q_ARG(QList<Pod>, pods));
}
}
void MainWindow::closeEvent(QCloseEvent *closeEvent) {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[closeEvent]";
#endif
saveSettings();
QMainWindow::closeEvent(closeEvent);
}
void MainWindow::loadSettings() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[loadSettings]";
#endif
QStringList repositories = _settings->value("local-repositories").toStringList();
ui->comboBoxCurrentRepository->addItems(repositories);
ui->comboBoxCurrentRepository->setCurrentText(_settings->value("active-repository").toString());
}
void MainWindow::saveSettings() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[saveSettings]";
#endif
QStringList repositories;
for(int i = 0; i < ui->comboBoxCurrentRepository->count(); i++) {
repositories.append(ui->comboBoxCurrentRepository->itemText(i));
}
_settings->setValue("local-repositories", repositories);
_settings->setValue("active-repository", ui->comboBoxCurrentRepository->currentText());
_settings->sync();
}
void MainWindow::installPodsFinished(QString repository, QList<Pod> pods, bool success) {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[installPodsFinished]";
#endif
_availablePodsSpinnerWidget->stop();
_localPodsSpinnerWidget->stop();
_developmentToolsSpinnerWidget->stop();
ui->tabWidget->setCurrentIndex(ui->tabWidget->indexOf(ui->tabLocalPods));
if(success) {
QMessageBox::information(this,
tr("Installing pods in %1").arg(repository),
tr("Finished installing %1 pods.").arg(pods.count()));
} else {
QMessageBox::information(this,
tr("Installing pods in %1").arg(repository),
tr("Installing some of the selected pods failed."));
}
refreshLocalPods();
}
void MainWindow::removePodsFinished(QString repository, QStringList podNames, bool success) {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[removePodsFinished]";
#endif
_localPodsSpinnerWidget->stop();
ui->tabWidget->setCurrentIndex(ui->tabWidget->indexOf(ui->tabLocalPods));
if(success) {
QMessageBox::information(this,
tr("Removing pods in %1").arg(repository),
tr("Finished removing %1 pods.").arg(podNames.count()));
} else {
QMessageBox::information(this,
tr("Removing pods in %1").arg(repository),
tr("Removing some of the selected pods failed."));
}
refreshLocalPods();
}
void MainWindow::updatePodsFinished(QString repository, QStringList podNames, bool success) {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[updatePodsFinished]";
#endif
_localPodsSpinnerWidget->stop();
ui->tabWidget->setCurrentIndex(ui->tabWidget->indexOf(ui->tabLocalPods));
if(success) {
QMessageBox::information(this,
tr("Updating pods in %1").arg(repository),
tr("Finished updating %1 pods.").arg(podNames.count()));
} else {
QMessageBox::information(this,
tr("Updating pods in %1").arg(repository),
tr("Updating some of the selected pods failed."));
}
refreshLocalPods();
}
void MainWindow::listInstalledPodsFinished(QString repository, QList<Pod> installedPods) {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[installedPodsFinished]";
#endif
Q_UNUSED(repository);
_localPods->setModelData(installedPods);
_localPodsSpinnerWidget->stop();
ui->tableViewLocal->resizeColumnsToContents();
}
void MainWindow::listAvailablePodsFinished(QStringList sources, QList<Pod> availablePods) {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[availablePodsFinished]";
#endif
Q_UNUSED(sources);
_remotePods->setModelData(availablePods);
_availablePodsSpinnerWidget->stop();
ui->tableViewRemote->resizeColumnsToContents();
}
void MainWindow::createProjectFinished(QString repository, bool success) {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[refreshLocalPods]";
#endif
if(success) {
ui->comboBoxCurrentRepository->addItem(repository);
ui->comboBoxCurrentRepository->setCurrentText(repository);
QMessageBox::information(this,
tr("Successfully created project"),
tr("Project has been created in \"%1\".").arg(repository));
} else {
QMessageBox::critical(this,
tr("Could not create project"),
tr("Failed to create project in \"%1\".").arg(repository));
}
}
void MainWindow::refreshLocalPods() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[refreshLocalPods]";
#endif
_localPodsSpinnerWidget->start();
QString repository = ui->comboBoxCurrentRepository->currentText();
if(!_podManager->isGitRepository(repository)) {
QMessageBox::warning(this,
tr("Invalid repository"),
tr("The directory you supplied does not appear to be the root of a valid git repository."));
int index;
while((index = ui->comboBoxCurrentRepository->findText(repository)) != -1) {
ui->comboBoxCurrentRepository->removeItem(index);
}
return;
}
metaObject()->invokeMethod(_podManager, "listInstalledPods", Q_ARG(QString, repository));
}
void MainWindow::refreshAvailablePods() {
#ifdef QT_DEBUG
qDebug() << __TIME__ << "[refreshAvailablePods]";
#endif
_availablePodsSpinnerWidget->start();
QStringList sources = _settings->value("sources").toStringList();
if(sources.isEmpty()) {
sources << "http://qt-pods.org/pods.json";
}
metaObject()->invokeMethod(_podManager, "listAvailablePods", Q_ARG(QStringList, sources));
}