File indexing completed on 2024-04-21 05:46:33

0001 // This license reflects the original Adept code:
0002 // -*- C++ -*- (c) 2008 Petr Rockai <me@mornfall.net>
0003 // Redistribution and use in source and binary forms, with or without
0004 // modification, are permitted provided that the following conditions are
0005 // met:
0006 //
0007 //     * Redistributions of source code must retain the above copyright
0008 //       notice, this list of conditions and the following disclaimer.
0009 //
0010 //     * Redistributions in binary form must reproduce the above
0011 //       copyright notice, this list of conditions and the following
0012 //       disclaimer in the documentation and/or other materials provided
0013 //       with the distribution.
0014 //
0015 //     * Neither the name of [original copyright holder] nor the names of
0016 //       its contributors may be used to endorse or promote products
0017 //       derived from this software without specific prior written
0018 //       permission.
0019 //
0020 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0021 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0022 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0023 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0024 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0026 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0027 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0028 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0029 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0030 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0031 /*
0032  * All the modifications below are licensed under this license
0033  * Copyright (C) 2010 Daniel Nicoletti <dantti12@gmail.com>
0034  *
0035  * This library is free software; you can redistribute it and/or
0036  * modify it under the terms of the GNU Library General Public
0037  * License as published by the Free Software Foundation; either
0038  * version 2 of the License, or (at your option) any later version.
0039  *
0040  * This library is distributed in the hope that it will be useful,
0041  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0042  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0043  * Library General Public License for more details.
0044  *
0045  * You should have received a copy of the GNU Library General Public License
0046  * along with this library; see the file COPYING.LIB. If not, write to
0047  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0048  * Boston, MA 02110-1301, USA.
0049  */
0050 
0051 #ifndef DEBCONF_GUI_H
0052 #define DEBCONF_GUI_H
0053 
0054 #include <QWidget>
0055 
0056 namespace DebconfKde {
0057 
0058 /**
0059  * \class DebconfGui DebconfGui.h DebconfGui
0060  * \author Daniel Nicoletti <dantti12@gmail.com>
0061  *
0062  * \brief Widget to present debconf elements
0063  *
0064  * This class provides a widget subclass that
0065  * can present Debconf elements (questions), using
0066  * a socket file.
0067  *
0068  * For this class to be useful the programs that are going
0069  * to use debconf to present questions must have the environment
0070  * variables DEBIAN_FRONTEND set to passthrough and DEBCONF_PIPE
0071  * to the path set on the constructor (\p socketName). Then when
0072  * a new connection arrives this class will take care of
0073  * talking the debconf protocol and emit activated() so that
0074  * this widget should be shown, and deactivated() when it should
0075  * be hidden.
0076  *
0077  * \note It is possible to let this class work automatically by
0078  * connecting the activated() signal on the QWidget::show() slot and
0079  * deactivated() on the QWidget::hide() slot.
0080  *
0081  * \note This class must not be deleted after deactivated() signal
0082  * is emitted, since new packages need to talk to the same socket.
0083  * Only delete it after you are sure no more operations ended.
0084  */
0085 class DebconfGuiPrivate;
0086 class Q_DECL_EXPORT DebconfGui : public QWidget
0087 {
0088     Q_OBJECT
0089 public:
0090     /**
0091      * Constructor that takes a file path (\p socketName) to create
0092      * a new socket.
0093      * \warning Be adivised that this class will delete the path pointed
0094      * by \p socketName. A good location would be /tmp/debconf-$PID.
0095      */
0096     explicit DebconfGui(const QString &socketName, QWidget *parent = 0);
0097 
0098     /**
0099      * Constructor that prepares for communication with Debconf via FIFO pipes.
0100      * Read (\p readfd) and write (\p writefd) file descriptors should be open
0101      * and connected to Debconf which speaks Passthrough frontend protocol.
0102      */
0103     explicit DebconfGui(int readfd, int writefd, QWidget *parent = 0);
0104 
0105     ~DebconfGui();
0106 
0107 Q_SIGNALS:
0108     /**
0109      * This signal is emitted when a new debconf element (question)
0110      * needs to be displayed.
0111      */
0112     void activated();
0113     /**
0114      * This signal is emitted when there are no more debconf element
0115      * (questions) to show. If FIFO pipes are used for communication, it means
0116      * that pipes were closed and futher communication is no longer possible.
0117      * If socket is used, more questions might still be shown in future so do
0118      * not delete this class.
0119      */
0120     void deactivated();
0121 
0122 private Q_SLOTS:
0123     void cmd_go(const QString &title, const QStringList &input);
0124     void cmd_progress(const QString &param);
0125 
0126     void on_nextPB_clicked();
0127     void on_backPB_clicked();
0128     void on_cancelPB_clicked();
0129 
0130 protected:
0131     /**
0132      * Reimplemented function to cancel the question if the user closes
0133      * the window.
0134      */
0135     void closeEvent(QCloseEvent *event) override;
0136 
0137     DebconfGuiPrivate * const d_ptr;
0138 
0139 private:
0140     Q_DECLARE_PRIVATE(DebconfGui)
0141 
0142     /**
0143       * This routine is called by all constructors to perform common
0144       * initialization.
0145       */
0146     void init();
0147 };
0148 
0149 
0150 }
0151 
0152 #endif