summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Schneider2013-12-02 14:27:55 +0100
committerManuel Schneider2013-12-02 14:27:55 +0100
commitbde1b4952610a8d6d369e1364a4d1743cb39c11b (patch)
tree868dbd87d678fe09305a646a7a0f47c03a790a0f
parent[Experimental] Timeout + revert functionality (diff)
downloadbeamergui-bde1b4952610a8d6d369e1364a4d1743cb39c11b.tar.gz
beamergui-bde1b4952610a8d6d369e1364a4d1743cb39c11b.tar.xz
beamergui-bde1b4952610a8d6d369e1364a4d1743cb39c11b.zip
Added config files
-rw-r--r--src/beamer.conf30
-rw-r--r--src/beamergui.pro2
-rw-r--r--src/config.cpp117
-rw-r--r--src/config.h45
-rw-r--r--src/main.cpp95
-rw-r--r--src/timeoutdialog.cpp3
-rw-r--r--src/timeoutdialog.h3
-rw-r--r--src/widget.cpp178
-rw-r--r--src/widget.h3
9 files changed, 160 insertions, 316 deletions
diff --git a/src/beamer.conf b/src/beamer.conf
index 2a6d0c3..e83f5a7 100644
--- a/src/beamer.conf
+++ b/src/beamer.conf
@@ -1,30 +1,4 @@
-[Modelines]
-# 16:10
-1/Modeline=1280x800 83.50 1280 1352 1480 1680 800 803 809 831 -hsync +vsync
-2/Modeline=1440x1050 106.50 1440 1528 1672 1904 900 903 909 934 -hsync +vsync
-3/Modeline=1680x1200 146.25 1680 1784 1960 2240 1050 1053 1059 1089 -hsync +vsync
-4/Modeline=1920x1200 193.25 1920 2056 2256 2592 1200 1203 1209 1245 -hsync +vsync
-5/Modeline=2560x1600 348.50 2560 2760 3032 3504 1600 1603 1609 1658 -hsync +vsync
-# 16:9
-6/Modeline=1280x720 74.50 1280 1344 1472 1664 720 723 728 748 -hsync +vsync
-7/Modeline=1368x768 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
-8/Modeline=1600x900 118.25 1600 1696 1856 2112 900 903 908 934 -hsync +vsync
-9/Modeline=1920x1080 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync
-10/Modeline=2560x1440 312.25 2560 2752 3024 3488 1440 1443 1448 1493 -hsync +vsync
-# 4:3
-11/Modeline=800x600 38.25 800 832 912 1024 600 603 607 624 -hsync +vsync
-12/Modeline=1024x768 63.50 1024 1072 1176 1328 768 771 775 798 -hsync +vsync
-13/Modeline=1152x864 81.75 1152 1216 1336 1520 864 867 871 897 -hsync +vsync
-14/Modeline=1280x960 101.25 1280 1360 1488 1696 960 963 967 996 -hsync +vsync
-15/Modeline=1400x1050 121.75 1400 1488 1632 1864 1050 1053 1057 1089 -hsync +vsync
-size=15
-
-[General]
-# Display to use
-display :0
-interface eth0
-
[SpecificSettings]
# IP specific configs
-1/IP=132.230.4.100 1280x900
-size=1
+132.230.4.100=1280x800
+132.230.4.26=1280x800
diff --git a/src/beamergui.pro b/src/beamergui.pro
index 6d72436..e8b5ab5 100644
--- a/src/beamergui.pro
+++ b/src/beamergui.pro
@@ -12,11 +12,9 @@ TEMPLATE = app
SOURCES += main.cpp\
widget.cpp \
- config.cpp \
timeoutdialog.cpp
HEADERS += widget.h \
- config.h \
timeoutdialog.h
FORMS += widget.ui
diff --git a/src/config.cpp b/src/config.cpp
deleted file mode 100644
index c8327f7..0000000
--- a/src/config.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-#include <QDebug>
-#include <QStringList>
-#include <stdio.h>
-#include <sys/types.h>
-#include <ifaddrs.h>
-#include <netinet/in.h>
-#include <string.h>
-#include <arpa/inet.h>
-#include "config.h"
-
-#define GROUP_GENERAL "General"
-#define GROUP_MODELINES "Modelines"
-#define GROUP_SPECIFIC "SpecificSettings"
-#define DISPLAY_KEY "display"
-#define DISPLAY_DEFAULT ":0"
-#define IFACE_KEY "interface"
-#define IFACE_DEFAULT "eth0"
-
-Config * Config::Instance = NULL;
-
-//_____________________________________________________________________________
-
-
-Config::Config()
-{
- // Defaults
- display = ":0";
- interface = "eth0";
-}
-
-//_____________________________________________________________________________
-
-
-void Config::loadSettings(QString _file)
-{
- // Open setting file
- settingsPath = _file;
- QSettings settings(settingsPath, QSettings::NativeFormat);
-
- // Get general information
- settings.beginGroup(GROUP_GENERAL);
- display = settings.value(DISPLAY_KEY, DISPLAY_DEFAULT).toString();
- interface = settings.value(IFACE_KEY, IFACE_DEFAULT).toString();
- settings.endGroup();
-
-
- /* Check for ip specific settings */
- // Get local ip
- QString IPV4 = getIPV4ofInterface(interface);
-
- // Find any information saved about this ip
- settings.beginGroup(GROUP_SPECIFIC);
- if ( settings.contains(IPV4) )
- ipSpecificXConf = settings.value(IPV4).toStringList();
- settings.endGroup();
-
-
- /* Get the "must-have-modelines" */
-
- int size = settings.beginReadArray(GROUP_MODELINES);
- for (int i = 0; i < size; ++i) {
- settings.setArrayIndex(i);
- qDebug()<< settings.value("Modeline").toString();
- modeLines.append(settings.value("Modeline").toString());
- }
- settings.endArray();
-
-
-
-// // Get all keys in this group (Keys are modenames)
-// QStringList modeKeys = settings.allKeys();
-
-// // Get the modeline for each key
-// for (QStringList::const_iterator i = modeKeys.constBegin(); i != modeKeys.constEnd(); ++i)
-// {
-// qDebug()<< "found" << *i;
-// // Prepend the name and save in list
-// modeLines.insert(*i, settings.value(*i).toStringList());
-// }
-// settings.endGroup();
-
-}
-
-//_____________________________________________________________________________
-
-
-QString Config::getIPV4ofInterface(QString _if) const
-{
- struct ifaddrs * ifAddrStruct=NULL;
- struct ifaddrs * ifa=NULL;
- void * tmpAddrPtr=NULL;
- QString result;
-
- 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, _if.toUtf8().constData()) == 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);
- result = addressBuffer;
- }
- }
-
- // clean up
- if (ifAddrStruct!=NULL)
- freeifaddrs(ifAddrStruct);
-
- return result;
-}
diff --git a/src/config.h b/src/config.h
deleted file mode 100644
index 7248d57..0000000
--- a/src/config.h
+++ /dev/null
@@ -1,45 +0,0 @@
-#ifndef CONIG_H
-#define CONIG_H
-
-#include <QString>
-#include <QList>
-#include <QStringList>
-#include <QMap>
-#include <QSettings>
-
-#define CONFIG_PATH "/home/manuel/beamer.conf"
-
-class Config
-{
- Config();
- ~Config();
-
- static Config * Instance;
-
- QString settingsPath;
- QString display;
- QString interface;
- QStringList ipSpecificXConf;
- QList<QString> modeLines;
-
- QString getIPV4ofInterface(QString) const;
-
-public:
-
- void loadSettings(QString);
-
- // Getters
- inline const QString& getSettingsPath() { return settingsPath; }
- inline const QString& getDisplay() { return display; }
- inline const QString& getInterface() { return interface; }
- inline const QStringList& getIpSpecificXConf(){ return ipSpecificXConf; }
- inline const QList<QString>& getModeLines() { return modeLines; }
-
- // Singleton //
- inline static Config * inst() {
- if (Instance == NULL) Instance = new Config();
- return Instance;
- }
-};
-
-#endif // CONIG_H
diff --git a/src/main.cpp b/src/main.cpp
index 584c121..9eb8a4b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,87 +1,30 @@
-
+// Copyright 2013, University of Freiburg,
+// Author: Manuel Schneider <ms1144>
#include <QtGui/QApplication>
-#include <QString>
-#include <QDebug>
#include <fstream>
#include <iostream>
#include "widget.h"
-#include "config.h"
-#include "x.h"
-
-
-// Prototypes
-QString getIP ();
-
-void usage()
-{
-}
-
int main(int argc, char *argv[])
{
-// if (argc != 1)
-// std::cout << "Usage: " << argv[0] << " <config file>" << std::endl;
-// else {
-// // Check if file exists
-// std::ifstream f(argv[1]);
-// if (!f) {
-// std::cerr << "The config file does not exist." << std::endl;
-// exit(1);
-// }
-// else
-// f.close();
-// }
-
-// //Load settings
-// Config::inst()->loadSettings(argv[1]);
-// qDebug() << X::Screen::inst();
-
-
-// qDebug() << Config::inst()->getDisplay();
-// qDebug() << Config::inst()->getInterface();
-// qDebug() << Config::inst()->getIpSpecificXConf();
-// qDebug() << Config::inst()->getModeLines();
-// qDebug() << Config::inst()->getSettingsPath();
-
-
-// // Get initial data (to be freed)
-// Display *dpy = XOpenDisplay(NULL);
-// XRRScreenResources *sr = XRRGetScreenResourcesCurrent(dpy, DefaultRootWindow(dpy));
-
-
-
-
-// int X=1;RandR::
-// int M=1;
-
-// XRROutputInfo *output_first_info = XRRGetOutputInfo(dpy, sr, sr->outputs[X]);
-
-// // XRRSet
-// // HOLY
-// XRRSetCrtcConfig(dpy,
-// sr,
-// output_first_info->crtc,
-// CurrentTime,
-// 0, 0,
-// sr->modes[output_first_info->npreferred -1].id,
-// RR_Rotate_0,
-// &sr->outputs[X],
-// 1);
-
-
-
-
-
-
-
-
-
-
- QApplication a(argc, argv);
- Widget w;
- w.show();
- return a.exec();
+ if (argc != 1)
+ std::cout << "Usage: " << argv[0] << " <config file>" << std::endl;
+ else {
+ // Check if file exists
+ std::ifstream f(argv[1]);
+ if (!f) {
+ std::cerr << "The config file does not exist." << std::endl;
+ exit(1);
+ }
+ else
+ f.close();
+ }
+
+ QApplication a(argc, argv);
+ Widget w;
+ w.show();
+ return a.exec();
}
diff --git a/src/timeoutdialog.cpp b/src/timeoutdialog.cpp
index 5a76504..8eb9aab 100644
--- a/src/timeoutdialog.cpp
+++ b/src/timeoutdialog.cpp
@@ -1,3 +1,6 @@
+// Copyright 2013, University of Freiburg,
+// Author: Manuel Schneider <ms1144>
+
#include "timeoutdialog.h"
#include <iostream>
#include <QProgressBar>
diff --git a/src/timeoutdialog.h b/src/timeoutdialog.h
index 643b593..a5278cb 100644
--- a/src/timeoutdialog.h
+++ b/src/timeoutdialog.h
@@ -1,3 +1,6 @@
+// Copyright 2013, University of Freiburg,
+// Author: Manuel Schneider <ms1144>
+
#ifndef TIMEOUTDIALOG_H
#define TIMEOUTDIALOG_H
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 <ms1144>
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <ifaddrs.h>
+#include <netinet/in.h>
+#include <string.h>
+#include <arpa/inet.h>
+
+#include <iostream>
+#include <algorithm>
#include <QString>
+#include <QDebug>
#include <QSet>
-#include <algorithm>
-#include <iostream>
-#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();
diff --git a/src/widget.h b/src/widget.h
index ad3077a..b80f714 100644
--- a/src/widget.h
+++ b/src/widget.h
@@ -1,3 +1,6 @@
+// Copyright 2013, University of Freiburg,
+// Author: Manuel Schneider <ms1144>
+
#ifndef WIDGET_H
#define WIDGET_H