small simplification, whitespace cleanup and dos2unix.
[Rockbox.git] / rbutil / rbutilqt / installzipwindow.cpp
blob551d1144c74b39fd6921c3fe33898ef7db46c0eb
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id: installzipwindow.cpp 14027 2007-07-27 17:42:49Z domonoky $
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "installzipwindow.h"
21 #include "ui_installprogressfrm.h"
24 InstallZipWindow::InstallZipWindow(QWidget *parent) : QDialog(parent)
26 ui.setupUi(this);
27 connect(ui.buttonBrowse, SIGNAL(clicked()), this, SLOT(browseFolder()));
30 void InstallZipWindow::setProxy(QUrl proxy_url)
32 proxy = proxy_url;
33 qDebug() << "Install::setProxy" << proxy;
36 void InstallZipWindow::setMountPoint(QString mount)
38 QFileInfo m(mount);
39 if(m.isDir()) {
40 ui.lineMountPoint->clear();
41 ui.lineMountPoint->insert(mount);
45 void InstallZipWindow::setUrl(QString path)
47 url = path;
50 void InstallZipWindow::browseFolder()
52 QFileDialog browser(this);
53 if(QFileInfo(ui.lineMountPoint->text()).isDir())
54 browser.setDirectory(ui.lineMountPoint->text());
55 else
56 browser.setDirectory("/media");
57 browser.setReadOnly(true);
58 browser.setFileMode(QFileDialog::DirectoryOnly);
59 browser.setAcceptMode(QFileDialog::AcceptOpen);
60 if(browser.exec()) {
61 qDebug() << browser.directory();
62 QStringList files = browser.selectedFiles();
63 setMountPoint(files.at(0));
67 void InstallZipWindow::accept()
69 downloadProgress = new QDialog(this);
70 dp.setupUi(downloadProgress);
72 // show dialog with error if mount point is wrong
73 if(QFileInfo(ui.lineMountPoint->text()).isDir()) {
74 mountPoint = ui.lineMountPoint->text();
75 userSettings->setValue("defaults/mountpoint", mountPoint);
77 else {
78 dp.listProgress->addItem(tr("Mount point is wrong!"));
79 dp.buttonAbort->setText(tr("&Ok"));
80 downloadProgress->show();
81 return;
84 userSettings->sync();
86 installer = new ZipInstaller(this);
88 QString fileName = url.section('/', -1);
90 installer->setFilename(fileName);
91 installer->setUrl(url);
92 installer->setProxy(proxy);
93 installer->setLogSection(logsection);
94 installer->setMountPoint(mountPoint);
95 installer->install(&dp);
97 connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
99 downloadProgress->show();
104 void InstallZipWindow::done(bool error)
106 qDebug() << "Install::done, error:" << error;
108 if(error)
110 // connect close button now as it's needed if we break upon an error
111 connect(dp.buttonAbort, SIGNAL(clicked()), downloadProgress, SLOT(close()));
112 return;
115 connect(dp.buttonAbort, SIGNAL(clicked()), this, SLOT(close()));
116 connect(dp.buttonAbort, SIGNAL(clicked()),downloadProgress, SLOT(close()));
119 void InstallZipWindow::setDeviceSettings(QSettings *dev)
121 devices = dev;
122 qDebug() << "Install::setDeviceSettings:" << devices;
125 void InstallZipWindow::setUserSettings(QSettings *user)
127 userSettings = user;