summaryrefslogblamecommitdiffstats
path: root/src/gui/clientConfigDialog.cpp
blob: 0ddada057cd158851cd6399af1e19e9d11db4d09 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                                                                
                  

                             
                               


                  
                                                 

                    

                                                         

                              




                                                                   
                                                                 

                                                 
                                                                                                            
 

                                                         
                                                                                






















                                                                                







                                                                                         









                                                    
 










                                                                




                                                                     
 
                                           
                                                                     
                                                
                                                                     
        
                                                                     
                                        
                                                                  
                                             
                                                                  
        

                                                                  

                         









                                                                                
/*
 # Copyright (c) 2009, 2010 - OpenSLX Project, Computer Center University of
 # Freiburg
 #
 # This program is free software distributed under the GPL version 2.
 # See http://openslx.org/COPYING
 #
 # If you have any feedback please consult http://openslx.org/feedback and
 # send your suggestions, praise, or complaints to feedback@openslx.org
 #
 # General information about OpenSLX can be found at http://openslx.org/
 # -----------------------------------------------------------------------------
 # clientConfigDialog.cpp
 #  - graphical interface
 #  - all configuration used by pvs/pvsgui is done here
 # -----------------------------------------------------------------------------
 */

#include <QtDebug>
#include <QNetworkInterface>
#include <QStandardItemModel>
#include "clientConfigDialog.h"
#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <src/net/pvsNetworkInterfaceListModel.h>

using namespace std;

ClientConfigDialog::ClientConfigDialog(QWidget *parent) :
        QDialog(parent),
        _interfaceListModel(0)
{
    setupUi(this);
    connect(this, SIGNAL(accepted()), this, SLOT(writeSettings()));
    connect(radioButtonOtherRO, SIGNAL(clicked()), this,
            SLOT(checkPermissions()));
    _interfaceListModel = new PVSNetworkInterfaceListModel(this);
    interfaceList->setModel(_interfaceListModel);
    interfaceList->setModelColumn(0);
    connect(reloadInterfaceListButton, SIGNAL(clicked()), _interfaceListModel, SLOT(reloadInterfaceList()));

    // connect to D-Bus and get interface
    QDBusConnection dbus = QDBusConnection::sessionBus();
    _ifaceDBus = new OrgOpenslxPvsInterface("org.openslx.pvs", "/", dbus, this);
}

ClientConfigDialog::~ClientConfigDialog()
{

}

////////////////////////////////////////////////////////////////////////////////
// Public

void ClientConfigDialog::open()
{
    readSettings();
    setVisible(true);
}

void ClientConfigDialog::readSettings()
{
    if (_settings.value("Display/location").isNull())
        comboBox->setCurrentIndex(1);
    else
        comboBox->setCurrentIndex(_settings.value("Display/location").toInt());

    QDBusPendingReply<QString> reply = _ifaceDBus->getConfigValue("multicast/interface");
    reply.waitForFinished();
    if (reply.isValid())
    {
        interfaceList->setEditText(reply.value());
    }

    reply = _ifaceDBus->getConfigValue("Permissions/vnc_lecturer");
    reply.waitForFinished();
    if (reply.isValid())
    {
        if (reply.value() == "rw")
            radioButtonLecturerRW->setChecked(true);
        else if (reply.value() == "ro")
            radioButtonLecturerRO->setChecked(true);
        else
            radioButtonLecturerNO->setChecked(true);
    }

    reply = _ifaceDBus->getConfigValue("Permissions/vnc_other");
    reply.waitForFinished();
    if (reply.isValid())
    {
        if (reply.value() == "rw")
            radioButtonOtherRW->setChecked(true);
        else if (reply.value() == "ro")
            radioButtonOtherRO->setChecked(true);
        else
            radioButtonOtherNO->setChecked(true);
    }
}

void ClientConfigDialog::writeSettings()
{
    _settings.setValue("Display/location", comboBox->currentIndex());

    if (radioButtonLecturerRW->isChecked())
        _ifaceDBus->setConfigValue("Permissions/vnc_lecturer", "rw");
    else if (radioButtonLecturerRO->isChecked())
        _ifaceDBus->setConfigValue("Permissions/vnc_lecturer", "ro");
    else
        _ifaceDBus->setConfigValue("Permissions/vnc_lecturer", "no");
    if (radioButtonOtherRW->isChecked())
        _ifaceDBus->setConfigValue("Permissions/vnc_other", "rw");
    else if (radioButtonOtherRO->isChecked())
        _ifaceDBus->setConfigValue("Permissions/vnc_other", "ro");
    else
        _ifaceDBus->setConfigValue("Permissions/vnc_other", "no");

    _settings.sync();
    emit configChanged();
}

////////////////////////////////////////////////////////////////////////////////
// Private

void ClientConfigDialog::checkPermissions()
{
    if (radioButtonLecturerNO->isChecked() && radioButtonOtherRO->isChecked())
        radioButtonLecturerRO->setChecked(true);
}