summaryrefslogtreecommitdiffstats
blob: 1f4058a97be867030d0afdbc5b10fd8756870346 (plain)
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
/*
 * Copyright (c) 2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <Swift/QtUI/QtUpdateFeedSelectionDialog.h>

#include <QComboBox>

#include <Swift/Controllers/Settings/SettingsProvider.h>

#include <Swift/QtUI/QtUISettingConstants.h>
#include <Swift/QtUI/SwiftUpdateFeeds.h>

namespace Swift {

QtUpdateFeedSelectionDialog::QtUpdateFeedSelectionDialog(SettingsProvider* settingsProvider) : QDialog(), settings_(settingsProvider) {
    ui.setupUi(this);

    connect(ui.currentChannelComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [&] (int newIndex) {
        setDescriptionForIndex(newIndex);
    });

    auto updateChannel = settings_->getSetting(QtUISettingConstants::SOFTWARE_UPDATE_CHANNEL);
    if (updateChannel == UpdateFeeds::StableChannel) {
        ui.currentChannelComboBox->setCurrentIndex(0);
    }
    else if (updateChannel == UpdateFeeds::TestingChannel) {
        ui.currentChannelComboBox->setCurrentIndex(1);
    }
    else if (updateChannel == UpdateFeeds::DevelopmentChannel) {
        ui.currentChannelComboBox->setCurrentIndex(2);
    }

    connect(this, &QDialog::accepted, [&]() {
        auto newUpdateChannel = std::string("");
        switch (ui.currentChannelComboBox->currentIndex()) {
            case 0:
                newUpdateChannel = UpdateFeeds::StableChannel;
                break;
            case 1:
                newUpdateChannel = UpdateFeeds::TestingChannel;
                break;
            case 2:
                newUpdateChannel = UpdateFeeds::DevelopmentChannel;
            break;
        }
        settings_->storeSetting(QtUISettingConstants::SOFTWARE_UPDATE_CHANNEL, newUpdateChannel);
    });

    setAttribute(Qt::WA_DeleteOnClose);
}

void QtUpdateFeedSelectionDialog::setDescriptionForIndex(int index) {
    switch (index) {
        case 0:
            ui.stableDescriptionLabel->show();
            ui.testingDescriptionLabel->hide();
            ui.developmentDescriptionLabel->hide();
            break;
        case 1:
            ui.stableDescriptionLabel->hide();
            ui.testingDescriptionLabel->show();
            ui.developmentDescriptionLabel->hide();
            break;
        case 2:
            ui.stableDescriptionLabel->hide();
            ui.testingDescriptionLabel->hide();
            ui.developmentDescriptionLabel->show();
            break;
        default:
            ui.stableDescriptionLabel->hide();
            ui.testingDescriptionLabel->hide();
            ui.developmentDescriptionLabel->hide();
            break;
    }
    setFixedSize(sizeHint());
}



}