From bde1b4952610a8d6d369e1364a4d1743cb39c11b Mon Sep 17 00:00:00 2001 From: Manuel Schneider Date: Mon, 2 Dec 2013 14:27:55 +0100 Subject: Added config files --- src/widget.cpp | 178 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 130 insertions(+), 48 deletions(-) (limited to 'src/widget.cpp') diff --git a/src/widget.cpp b/src/widget.cpp index dda729a..78afbd7 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -1,21 +1,26 @@ -#include "widget.h" -#include "ui_widget.h" -#include "config.h" +// Copyright 2013, University of Freiburg, +// Author: Manuel Schneider + +#include +#include +#include +#include +#include +#include + +#include +#include #include +#include #include -#include -#include -#include "timeoutdialog.h" +#include "widget.h" +#include "ui_widget.h" +#include "timeoutdialog.h" -//void setRefreshSpeed::on_okButton_clicked() -//{ -// QApplication::beep(); -// MainWindow::freq = ui->spinBox->value(); -// ui->setupUi(this); -// setRefreshSpeed::close(); -//} +#define INTERFACE "eth0" +#define GROUP_SPECIFIC "SpecificSettings" //___________________________________________________________________________ Widget::Widget(QWidget *parent) : @@ -65,6 +70,89 @@ Widget::Widget(QWidget *parent) : } + // Get the ip adress of the interface + struct ifaddrs * ifAddrStruct=NULL; + struct ifaddrs * ifa=NULL; + void * tmpAddrPtr=NULL; + QString ipV4; + getifaddrs(&ifAddrStruct); + // Iterate through the adresses. + for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) { + // If the address is IP V4 and the interface is _if + if (ifa ->ifa_addr->sa_family==AF_INET + && ( strcmp(ifa->ifa_name, INTERFACE) == 0) ) { + // Get the IP + tmpAddrPtr=&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr; + // convert to readable form + char addressBuffer[INET_ADDRSTRLEN]; + inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN); + ipV4 = addressBuffer; + } + } + // clean up + if (ifAddrStruct!=NULL) + freeifaddrs(ifAddrStruct); + + // Open Qsettings file + QSettings settings(QCoreApplication::arguments()[1], QSettings::NativeFormat); + + // Find any information saved about this ip. This config is assumed + // to be tested on this system and will be applied immediately. + settings.beginGroup(GROUP_SPECIFIC); + if ( settings.contains(ipV4) ) { + qDebug() << ipV4 ; + // First get a useful representation + unsigned int width, height; + QStringList modeAsStrings = + settings.value(ipV4) + .toString().split("x", QString::SkipEmptyParts); + width = modeAsStrings.at(0).toInt(); + height = modeAsStrings.at(1).toInt(); + + // Find a mode that matches the string + // No sanity check here as the modes have to exist and be tested + RRMode m1,m2; + for (int i = 0; i < _outputMap[_monitor]->nmode; ++i){ + if ( width == _modeMap[_outputMap[_monitor]->modes[i]]->width + && height == _modeMap[_outputMap[_monitor]->modes[i]]->height ) + m1 = _modeMap[_outputMap[_monitor]->modes[i]]->id; + } + for (int i = 0; i < _outputMap[_beamer]->nmode; ++i){ + if ( width == _modeMap[_outputMap[_beamer]->modes[i]]->width + && height == _modeMap[_outputMap[_beamer]->modes[i]]->height ) + m2 = _modeMap[_outputMap[_beamer]->modes[i]]->id; + } + + // Set screensize + XRRSetScreenSize(_display, DefaultRootWindow(_display), + width, + height, + 25.4 * width / 96, // standard dpi that X uses + 25.4 * height / 96); // standard dpi that X uses + + // Apply the modes + XRRSetCrtcConfig(_display, + _screenResources, + _outputMap[_monitor]->crtc, + CurrentTime, + 0, 0, + m1, + RR_Rotate_0, + &_monitor, 1); + + XRRSetCrtcConfig(_display, + _screenResources, + _outputMap[_beamer]->crtc, + CurrentTime, + 0, 0, + m2, + RR_Rotate_0, + &_beamer, 1); + + + } + settings.endGroup(); + // Check if the beamer transmitted reliable data. bool gotEDID = false; int nprop; @@ -327,52 +415,30 @@ void Widget::handleButton() _screenResources, _outputMap[_monitor]->crtc, CurrentTime, - 0, 0, - m1, + 0, 0, m1, RR_Rotate_0, &_monitor, 1); - XRRSetCrtcConfig(_display, _screenResources, _outputMap[_beamer]->crtc, CurrentTime, - 0, 0, - m2, + 0, 0, m2, RR_Rotate_0, &_beamer, 1); - -// // Apply the change -// QProcess p; -// QStringList arguments; -// arguments << "--output" << _outputMap[_monitor]->name -// << "--mode" << _ui->comboBox->currentText() -// << "--output" << _outputMap[_beamer]->name -// << "--mode" << _ui->comboBox->currentText() -// << "--same-as" <<_outputMap[_monitor]->name; -// p.start("xrandr", arguments); -// p.waitForFinished(); - -// // First get a useful representation -// unsigned int width, height; -// QStringList modeAsStrings = _ui->comboBox->currentText().split("x", QString::SkipEmptyParts); -// width = modeAsStrings.at(0).toInt(); -// height = modeAsStrings.at(1).toInt(); - - // Center dialog on screenbottom - - // Center dialog on screenbottom - const QRect desktopRect = QApplication::desktop()->screenGeometry(); - this->move( desktopRect.width()/2-this->width()/2, - desktopRect.height()-this->height()); + // Center widget on screenbottom + this->move( width/2 - this->width()/2, height - this->height()); // Show a dialog asking if the res should be kept - TimeOutDialog *t = new TimeOutDialog(5, this); - t->setWindowModality(Qt::WindowModal); - t->setLabelText("Keep resolution?"); + TimeOutDialog *t = new TimeOutDialog(5, this);/* + t->setWindowModality(Qt::WindowModal);*/ + t->setLabelText("Do you want to keep this resolution?"); t->setCancelButtonText("Keep"); t->exec(); + // Center the dialog + t->move( width/2 - this->width()/2, height/2 - this->height()); + // If the dialog was not canceled revert the resolution if ( ! t->wasCanceled()) { @@ -423,9 +489,9 @@ void Widget::handleButton() it.value()->noutput); } - const QRect desktopRect = QApplication::desktop()->screenGeometry(); - this->move( desktopRect.width()/2-this->width()/2, - desktopRect.height()-this->height()); + // Again center dialog on screenbottom + this->move( ScreenSize.width()/2 - this->width()/2, + ScreenSize.height() - this->height()); } // End of Revert section @@ -436,3 +502,19 @@ void Widget::handleButton() delete it.value(); } } + + + +/////////////////////////// CODE PAPIERKORB ///////////////////////////////// + + +// // Apply the mode via xrandr +// QProcess p; +// QStringList arguments; +// arguments << "--output" << _outputMap[_monitor]->name +// << "--mode" << _ui->comboBox->currentText() +// << "--output" << _outputMap[_beamer]->name +// << "--mode" << _ui->comboBox->currentText() +// << "--same-as" <<_outputMap[_monitor]->name; +// p.start("xrandr", arguments); +// p.waitForFinished(); -- cgit v1.2.3-55-g7522