2 * Copyright (c) 2004 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Shawn R. Walker <adonijah@gmail.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $Id: mainwindow.cpp,v 1.19 2004/11/06 18:17:51 cpressey Exp $
35 * $DragonFly: src/contrib/bsdinstaller-1.1.6/src/frontends/qt/src/mainwindow.cpp,v 1.1.1.1 2008/03/12 22:15:53 dave Exp $
42 #include "mainwindow.h"
44 MainWindow::MainWindow(QWidget *parent, const char *name)
45 : QMainWindow(parent, name)
52 setCaption(tr("The BSD Installer"));
53 setIcon(QPixmap::fromMimeSource("icon.png"));
55 connection = dfui_connection_new(DFUI_TRANSPORT_TCP, "9999");
56 dfui_fe_connect(connection);
60 form = new Form(this, NULL, connection);
61 setCentralWidget(form);
64 void MainWindow::createActions()
66 exitAct = new QAction(tr("E&xit"), tr("Ctrl+Q"), this);
67 exitAct->setStatusTip(tr("Exit the application"));
68 connect(exitAct, SIGNAL(activated()), this, SLOT(close()));
70 aboutAct = new QAction(tr("&About"), 0, this);
71 aboutAct->setStatusTip(tr("Show the application's About box"));
72 connect(aboutAct, SIGNAL(activated()), this, SLOT(about()));
74 aboutQtAct = new QAction(tr("About &Qt"), 0, this);
75 aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
76 connect(aboutQtAct, SIGNAL(activated()), qApp, SLOT(aboutQt()));
79 void MainWindow::createMenus()
81 fileMenu = new QPopupMenu(this);
82 exitAct->addTo(fileMenu);
84 helpMenu = new QPopupMenu(this);
85 aboutAct->addTo(helpMenu);
86 aboutQtAct->addTo(helpMenu);
88 menuBar()->insertItem(tr("&File"), fileMenu);
89 menuBar()->insertSeparator();
90 menuBar()->insertItem(tr("&Help"), helpMenu);
93 bool MainWindow::message(DFUI_MSG msg, const char *message, bool confirm)
97 if (msg == DFUI_INFORMATION) {
98 ret = QMessageBox::information(this, tr("Information"), tr(message),
99 confirm ? QMessageBox::Yes : NULL,
100 confirm ? QMessageBox::No | QMessageBox::Default : NULL);
101 } else if (msg == DFUI_QUESTION) {
102 ret = QMessageBox::question(this, tr("Question"), tr(message),
103 confirm ? QMessageBox::Yes : NULL,
104 confirm ? QMessageBox::No | QMessageBox::Default : NULL);
105 } else if (msg == DFUI_WARNING) {
106 ret = QMessageBox::warning(this, tr("Warning"), tr(message),
107 confirm ? QMessageBox::Yes : NULL,
108 confirm ? QMessageBox::No | QMessageBox::Default : NULL);
109 } else if (msg == DFUI_CRITICAL) {
110 ret = QMessageBox::critical(this, tr("Critical"), tr(message),
111 confirm ? QMessageBox::Yes : NULL,
112 confirm ? QMessageBox::No | QMessageBox::Default : NULL);
115 if (ret == QMessageBox::Yes || ret == QMessageBox::Ok)
121 void MainWindow::about()
123 QMessageBox::about(this, tr("About The BSD Installer"),
124 tr("<h2>The BSD Installer 1.0</h2>"
125 "<p>Copyright © 2004 The DragonFly Project.</p>"));
128 void MainWindow::showEvent(QShowEvent *)
130 myTimerId = startTimer(150); // Process dfuibe events every 150ms
133 void MainWindow::closeEvent(QCloseEvent *event)
135 if (message(DFUI_CRITICAL, tr("Are you sure you want to exit?"))) {
137 killTimer(myTimerId);
138 dfui_fe_abort(connection);
139 dfui_fe_disconnect(connection);
145 void MainWindow::timerEvent(QTimerEvent *event)
149 struct dfui_property *gp;
152 if ((event->timerId() == myTimerId) && !form->processing) {
153 dfui_fe_receive(connection, &msgtype, &payload);
156 case DFUI_BE_MSG_PRESENT:
157 form->present((struct dfui_form *)payload);
160 case DFUI_BE_MSG_PROG_BEGIN:
161 form->present((struct dfui_progress *)payload);
162 dfui_progress_free((struct dfui_progress *)payload);
163 dfui_fe_progress_continue(connection);
164 qApp->processEvents();
167 case DFUI_BE_MSG_PROG_UPDATE:
168 qApp->processEvents();
169 form->setProgress(dfui_progress_get_amount(
170 (struct dfui_progress *)payload));
172 if (dfui_progress_get_streaming((struct dfui_progress *)payload)) {
173 form->updateProgressText(
174 dfui_progress_get_msg_line(
175 (struct dfui_progress *)payload));
179 dfui_fe_progress_cancel(connection);
181 dfui_fe_progress_continue(connection);
183 dfui_progress_free((struct dfui_progress *)payload);
184 qApp->processEvents();
187 case DFUI_BE_MSG_PROG_END:
188 form->setProgress(-1);
189 dfui_fe_progress_continue(connection);
190 qApp->processEvents();
193 case DFUI_BE_MSG_SET_GLOBAL:
194 gp = (struct dfui_property *)payload;
197 * Check for a change to the "lang" setting...
199 if (strcmp(dfui_property_get_name(gp), "lang") == 0) {
201 * TODO: call the appropriate gettext function.
205 dfui_fe_confirm_set_global(connection);
206 dfui_property_free(gp);
209 case DFUI_BE_MSG_STOP:
210 dfui_fe_confirm_stop(connection);
211 dfui_fe_disconnect(connection);