summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/install.cpp
blob: 948cf2005aa2a62a268d5430c4f13b6e8e1385f9 (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
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
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 *
 *   Copyright (C) 2007 by Dominik Riebeling
 *   $Id$
 *
 * All files in this archive are subject to the GNU General Public License.
 * See the file COPYING in the source tree root for full license agreement.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include "install.h"
#include "ui_installfrm.h"
#include "ui_installprogressfrm.h"


Install::Install(QWidget *parent) : QDialog(parent)
{
    ui.setupUi(this);

    connect(ui.radioCurrent, SIGNAL(toggled(bool)), this, SLOT(setCached(bool)));
    connect(ui.radioStable, SIGNAL(toggled(bool)), this, SLOT(setDetailsStable(bool)));
    connect(ui.radioCurrent, SIGNAL(toggled(bool)), this, SLOT(setDetailsCurrent(bool)));
    connect(ui.radioArchived, SIGNAL(toggled(bool)), this, SLOT(setDetailsArchived(bool)));
    connect(ui.buttonBrowse, SIGNAL(clicked()), this, SLOT(browseFolder()));
}


void Install::setCached(bool cache)
{
    ui.checkBoxCache->setEnabled(!cache);
}


void Install::setReleased(QString rel)
{
    releasever = rel;
    if(!rel.isEmpty()) {
        ui.radioStable->setChecked(true);
        ui.radioStable->setEnabled(true);
        QFont font;
        font.setBold(true);
        ui.radioStable->setFont(font);
    }
    else {
        ui.radioCurrent->setChecked(true);
        ui.radioStable->setEnabled(false);
        ui.radioStable->setChecked(false);
        QFont font;
        font.setBold(true);
        ui.radioCurrent->setFont(font);
    }
    qDebug() << "Install::setReleased" << releasever;

}


void Install::setProxy(QUrl proxy_url)
{
    proxy = proxy_url;
    qDebug() << "Install::setProxy" << proxy;
}


void Install::setMountPoint(QString mount)
{
    QFileInfo m(mount);
    if(m.isDir()) {
        ui.lineMountPoint->clear();
        ui.lineMountPoint->insert(mount);
    }
}


void Install::browseFolder()
{
    QFileDialog browser(this);
    if(QFileInfo(ui.lineMountPoint->text()).isDir())
        browser.setDirectory(ui.lineMountPoint->text());
    else
        browser.setDirectory("/media");
    browser.setReadOnly(true);
    browser.setFileMode(QFileDialog::DirectoryOnly);
    browser.setAcceptMode(QFileDialog::AcceptOpen);
    if(browser.exec()) {
        qDebug() << browser.directory();
        QStringList files = browser.selectedFiles();
        setMountPoint(files.at(0));
    }
}


void Install::accept()
{
    QDialog *downloadProgress = new QDialog(this);
    dp.setupUi(downloadProgress);
    // connect close button now as it's needed if we break upon an error
    connect(dp.buttonAbort, SIGNAL(clicked()), downloadProgress, SLOT(close()));
    // show dialog with error if mount point is wrong
    if(QFileInfo(ui.lineMountPoint->text()).isDir()) {
        mountPoint = ui.lineMountPoint->text();
        userSettings->setValue("defaults/mountpoint", mountPoint);
    }
    else {
        dp.listProgress->addItem(tr("Mount point is wrong!"));
        dp.buttonAbort->setText(tr("&Ok"));
        downloadProgress->show();
        return;
    }

    if(ui.radioStable->isChecked()) {
        file = "stable"; // FIXME: this is wrong!
        fileName = QString("rockbox.zip");
        userSettings->setValue("defaults/build", "stable");
    }
    else if(ui.radioArchived->isChecked()) {
        file = QString("%1%2/rockbox-%3-%4.zip")
            .arg(devices->value("daily_url").toString(),
            userSettings->value("defaults/platform").toString(),
            userSettings->value("defaults/platform").toString(),
            archived);
        fileName = QString("rockbox-%1-%2.zip")
            .arg(userSettings->value("defaults/platform").toString(),
            archived);
        userSettings->setValue("defaults/build", "archived");
    }
    else if(ui.radioCurrent->isChecked()) {
        file = QString("%1%2/rockbox.zip")
            .arg(devices->value("bleeding_url").toString(),
        userSettings->value("defaults/platform").toString());
        fileName = QString("rockbox.zip");
        userSettings->setValue("defaults/build", "current");
    }
    else {
        qDebug() << "no build selected -- this shouldn't happen";
        return;
    }
    userSettings->sync();

    installer = new ZipInstaller(this);
    installer->setFilename(fileName);
    installer->setUrl(file);
    installer->setProxy(proxy);
    installer->setLogSection("rockboxbase");
    installer->setMountPoint(mountPoint);
    installer->install(&dp);
    
    connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));    
    
    downloadProgress->show();
}


void Install::done(bool error)
{
    qDebug() << "Install::done, error:" << error;

    if(error)
    {
        connect(dp.buttonAbort, SIGNAL(clicked()), this, SLOT(close()));
        return;
    }
      
    connect(dp.buttonAbort, SIGNAL(clicked()), this, SLOT(close()));
    delete installer;
}


void Install::setDetailsCurrent(bool show)
{
    if(show) {
        ui.labelDetails->setText(tr("This is the absolute up to the minute "
                "Rockbox built. A current build will get updated every time "
                "a change is made."));
        if(releasever == "")
            ui.labelNote->setText(tr("<b>Note:</b> This option will always "
                "download a fresh copy. "
                "<b>This is the recommended version.</b>"));
        else
            ui.labelNote->setText(tr("<b>Note:</b> This option will always "
                "download a fresh copy."));
    }
}


void Install::setDetailsStable(bool show)
{
    if(show) {
        ui.labelDetails->setText(
            tr("This is the last released version of Rockbox."));

        if(releasever != "") ui.labelNote->setText(tr("<b>Note:</b>"
            "The lastest released version is %1. "
            "<b>This is the recommended version.</b>").arg(releasever));
        else ui.labelNote->setText("");
    }
}


void Install::setDetailsArchived(bool show)
{
    if(show) {
        ui.labelDetails->setText(tr("These are automatically built each day "
        "from the current development source code. This generally has more "
        "features than the last release but may be much less stable. "
        "Features may change regularly."));
        ui.labelNote->setText(tr("<b>Note:</b> archived version is %1.")
            .arg(archived));
    }
}


void Install::setDeviceSettings(QSettings *dev)
{
    devices = dev;
    qDebug() << "Install::setDeviceSettings:" << devices;
}


void Install::setArchivedString(QString string)
{
    archived = string;
    if(archived.isEmpty()) {
        ui.radioArchived->setEnabled(false);
        qDebug() << "no information about archived version available!";
    }
    qDebug() << "Install::setArchivedString" << archived;
}

void Install::setUserSettings(QSettings *user)
{
    userSettings = user;
}