summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2024-05-08 18:51:13 +0200
committerSimon Rettberg2024-05-08 18:51:13 +0200
commit4cf1feb0b7b2854c43aaab534a2301eca0c25b4d (patch)
treefd66caef9b5191c264c7b4e81b0f9468dae774e8 /src
parentTurn deprecated-declarations into warning (diff)
downloadvmchooser2-4cf1feb0b7b2854c43aaab534a2301eca0c25b4d.tar.gz
vmchooser2-4cf1feb0b7b2854c43aaab534a2301eca0c25b4d.tar.xz
vmchooser2-4cf1feb0b7b2854c43aaab534a2301eca0c25b4d.zip
Support CoW, and selecting between edit and copy
Diffstat (limited to 'src')
-rw-r--r--src/config.cpp1
-rw-r--r--src/config.h1
-rw-r--r--src/dialog.cpp103
-rw-r--r--src/dialog.h4
-rw-r--r--src/main.cpp2
-rw-r--r--src/session.h8
-rw-r--r--src/ui/dialog.ui37
-rw-r--r--src/vsession.h10
8 files changed, 132 insertions, 34 deletions
diff --git a/src/config.cpp b/src/config.cpp
index ca83bfc..16fdf56 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -68,6 +68,7 @@ const ConfigOption* const Config::TEMPLATE_MODE = new ConfigOption("", "template
const ConfigOption* const Config::AUTOSTART_UUID = new ConfigOption("", "start-uuid", "start-uuid", "uuid", "", "Immediately launch session with given uuid/name");
const ConfigOption* const Config::NO_VTX = new ConfigOption("", "no-vtx", "no-vtx", "", "0", "Fade all VM sessions that would require VTX/SVM CPU capabilities");
const ConfigOption* const Config::DUMP_CONFIG = new ConfigOption("", "dump-config", "", "", "", "Dump effective configuration (config file plus command line options) to stdout");
+const ConfigOption* const Config::COW_TOKEN = new ConfigOption("", "cow-token", "cow-token", "token", "", "Use given token for edit mode");
QString Config::get(const ConfigOption* const option)
diff --git a/src/config.h b/src/config.h
index a1eecec..24a613d 100644
--- a/src/config.h
+++ b/src/config.h
@@ -36,6 +36,7 @@ public:
static const ConfigOption* const AUTOSTART_UUID;
static const ConfigOption* const NO_VTX;
static const ConfigOption* const DUMP_CONFIG;
+ static const ConfigOption* const COW_TOKEN;
static bool init(const QCoreApplication& app, const ConfigOption* const configFile);
static QString get(const ConfigOption* const option);
diff --git a/src/dialog.cpp b/src/dialog.cpp
index aea2d6e..9dfff00 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -12,9 +12,9 @@
#include <QTemporaryFile>
#include <QUrlQuery>
-#include "unistd.h"
-#include "stdio.h"
-#include "sys/wait.h"
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/wait.h>
#include "ui_dialog.h"
#include "sessiontreeitem.h"
@@ -95,8 +95,10 @@ Dialog::Dialog(QWidget *parent)
this->onTabButtonChanged(TAB_NATIVE);
}
- ui->chkAdminMode->setVisible(Config::isSet(Config::ALLOW_VM_EDIT));
- ui->chkAdminMode->setEnabled(false);
+ ui->chkAdminEdit->setVisible(Config::isSet(Config::ALLOW_VM_EDIT));
+ ui->chkAdminEdit->setEnabled(false);
+ ui->chkAdminCopy->setVisible(Config::isSet(Config::ALLOW_VM_EDIT));
+ ui->chkAdminCopy->setEnabled(false);
ui->btnScreenSetup->setVisible(isProcessRunning("beamergui"));
if (QApplication::screens().size() > 1) {
@@ -110,6 +112,16 @@ Dialog::Dialog(QWidget *parent)
QObject::connect(SessionsIconHolder::get(), &SessionsIconHolder::iconDownloaded,
this, &Dialog::iconDownloaded);
+ QObject::connect(ui->chkAdminCopy, &QCheckBox::toggled, [this](bool checked) {
+ if (checked) {
+ ui->chkAdminEdit->setChecked(false);
+ }
+ });
+ QObject::connect(ui->chkAdminEdit, &QCheckBox::toggled, [this](bool checked) {
+ if (checked) {
+ ui->chkAdminCopy->setChecked(false);
+ }
+ });
}
Dialog::~Dialog() {
@@ -143,6 +155,21 @@ void Dialog::on_treeView_doubleClicked(const QModelIndex& index)
if (!s->prepareRun())
return;
+ bool adminMode = false;
+
+ if (anyEditModeRequested() && s->canEdit()) {
+ auto mode = s->editModeTypes();
+ adminMode = true;
+ if (ui->chkAdminEdit->isChecked() && ui->chkAdminEdit->isEnabled()) {
+ setenv("VMCHOOSER_ADMIN_TYPE", "EDIT", 1);
+ } else {
+ setenv("VMCHOOSER_ADMIN_TYPE", "COPY", 1);
+ }
+ if (Config::isSet(Config::COW_TOKEN)) {
+ setenv("VMCHOOSER_ADMIN_TOKEN", Config::get(Config::COW_TOKEN).toLocal8Bit().constData(), 1);
+ }
+ }
+
WindowManager::stopOwnInstance(true);
// These two are up here in case run-virt cares...
@@ -153,7 +180,12 @@ void Dialog::on_treeView_doubleClicked(const QModelIndex& index)
setenv("PVS_AUTO_CONNECT", "FALSE", 1);
}
}
- if (ui->chkAdminMode->isEnabled() && ui->chkAdminMode->isChecked()) {
+
+ if (anyEditModeRequested() && Config::isSet(Config::ALLOW_VM_EDIT)) {
+ adminMode = true;
+ }
+
+ if (adminMode) {
setenv("VMCHOOSER_ADMIN_MODE", "TRUE", 1);
} else {
setenv("VMCHOOSER_ADMIN_MODE", "FALSE", 1);
@@ -198,6 +230,12 @@ void Dialog::on_treeView_doubleClicked(const QModelIndex& index)
QApplication::instance()->quit();
}
+bool Dialog::anyEditModeRequested() const
+{
+ return (ui->chkAdminEdit->isEnabled() && ui->chkAdminEdit->isChecked())
+ || (ui->chkAdminCopy->isEnabled() && ui->chkAdminCopy->isChecked());
+}
+
void Dialog::on_treeView_expanded(const QModelIndex& index) {
if (activeTab_ != TAB_ALL_VMS)
return;
@@ -457,26 +495,42 @@ void Dialog::onCenterTimer() {
/**
* Download lecture list, news and help
*/
-void Dialog::downloadData(const QString& locationIds) {
+void Dialog::downloadData() {
QUrl listUrl(Config::isSet(Config::URL_LIST)
? Config::get(Config::URL_LIST)
: Config::get(Config::URL_BASE).append("/list"));
QUrlQuery listQuery(listUrl);
+ bool cache = true;
+ const QString& locationIds = Config::get(Config::LOCATIONS);
+ const QString& cowToken = Config::get(Config::COW_TOKEN);
if (!locationIds.isEmpty()) {
listQuery.addQueryItem("locations", locationIds);
}
+ if (!cowToken.isEmpty()) {
+ // Don't cache lecture list containing edit mode annotations
+ listQuery.addQueryItem("cow-user", cowToken);
+ cache = false;
+ }
if (Config::isSet(Config::EXAM_MODE)) {
listQuery.addQueryItem("exams", "exam-mode");
}
listUrl.setQuery(listQuery);
//
// Download lecture XML
- FileDownloader::download(listUrl, [this](QNetworkReply::NetworkError err, const QByteArray& data) {
+ FileDownloader::download(listUrl, [cache, this](QNetworkReply::NetworkError err, const QByteArray& data) {
QList<Session*> sessions;
- QDomDocument doc = toDomDocument(QStringLiteral("lecture list"), data, TEMP_PATH_XML_LIST, QStringLiteral("settings"));
+ QDomDocument doc = toDomDocument(QStringLiteral("lecture list"), data, cache ? TEMP_PATH_XML_LIST : QString(),
+ QStringLiteral("settings"));
sessions = VSession::loadFromXmlDocument(doc);
+ QString errMsg = doc.firstChildElement(QStringLiteral("settings"))
+ .firstChildElement(QStringLiteral("error")).text();
+
+ if (!errMsg.isEmpty()) {
+ ui->filterEdit->setText(errMsg);
+ }
+
this->removeStatusString(STR_LOADING);
if (sessions.isEmpty()) {
if (err == QNetworkReply::NoError) {
@@ -489,13 +543,14 @@ void Dialog::downloadData(const QString& locationIds) {
this->addItems(sessions, TAB_ALL_VMS);
bool showEdit = false; // Only show edit button if at least one lecture is editable
for (QList<Session*>::const_iterator it = sessions.begin(); it != sessions.end(); ++it) {
- if (reinterpret_cast<VSession*>(*it)->canEdit()) {
+ if ((**it).canEdit()) {
showEdit = true;
break;
}
}
if (showEdit) {
- ui->chkAdminMode->setVisible(true);
+ ui->chkAdminEdit->setVisible(true);
+ ui->chkAdminCopy->setVisible(true);
}
}
@@ -559,11 +614,16 @@ void Dialog::mousePressEvent(QMouseEvent * event) {
userInteracted_ = true;
}
+void Dialog::setAdminChecks(int mode)
+{
+ ui->chkAdminEdit->setEnabled((mode & Session::EDIT_TYPE_EDIT) != 0);
+ ui->chkAdminCopy->setEnabled((mode & Session::EDIT_TYPE_COPY) != 0);
+}
+
void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelIndex&) {
- SessionTreeItem* item =
- static_cast<SessionTreeItem*>(current.internalPointer());
+ SessionTreeItem* item = static_cast<SessionTreeItem*>(current.internalPointer());
if (item == nullptr) {
- ui->chkAdminMode->setEnabled(false);
+ setAdminChecks(0);
return;
}
@@ -571,7 +631,7 @@ void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelI
if (!s) {
qDebug() << "invalid selection";
// no valid session has been selected, do nothing
- ui->chkAdminMode->setEnabled(false);
+ setAdminChecks(0);
return;
}
@@ -588,8 +648,12 @@ void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelI
ui->label_platform->setText(vs->getAttribute("virtualizer_name", "param"));
ui->label_platform->setToolTip(vs->getAttribute("virtualizer_name", "param"));
- // TODO: This is a bug? vs->canEdit() seems completely pointless right now...
- ui->chkAdminMode->setEnabled(vs->canEdit() || Config::isSet(Config::ALLOW_VM_EDIT));
+ // If ALLOW_EDIT is false, we still might have editable sessions if the list meta data says so
+ if (Config::isSet(Config::ALLOW_VM_EDIT)) {
+ setAdminChecks(255);
+ } else {
+ setAdminChecks(s->editModeTypes());
+ }
if (vs->keywords().length() > 0) {
description = "\n\nKeywords: ";
@@ -603,6 +667,7 @@ void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelI
ui->label_os->setText(QCoreApplication::instance()->translate("Dialog", "Native Linux"));
ui->label_platform->setText("Linux");
ui->label_platform->setToolTip("");
+ setAdminChecks(0);
}
ui->label_name->setText(s->shortDescription());
ui->label_name->setToolTip(s->shortDescription());
@@ -877,6 +942,10 @@ static QDomDocument toDomDocument(const QString& what, const QByteArray& data, c
} else {
qDebug() << "No content downloaded for" << what;
}
+ // No backup file given, just return what we got
+ if (backupFile.isEmpty())
+ return doc;
+
QFile backup(backupFile);
if (doc.isNull() || !doc.hasChildNodes()) {
if (backup.open(QFile::ReadOnly)) {
diff --git a/src/dialog.h b/src/dialog.h
index d9c5d6b..651833f 100644
--- a/src/dialog.h
+++ b/src/dialog.h
@@ -40,7 +40,7 @@ class Dialog : public QDialog {
void selectPreviousSession();
void setTheme();
void startSession(const QString& name);
- void downloadData(const QString& locationIds);
+ void downloadData();
static QDialog* getInstance();
protected: // Overrides
@@ -69,6 +69,8 @@ class Dialog : public QDialog {
void selectFirstElement();
void checkAutostart();
+ bool anyEditModeRequested() const;
+ void setAdminChecks(int mode);
private slots:
void on_pushButtonStart_clicked();
diff --git a/src/main.cpp b/src/main.cpp
index df7309c..e1a3499 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -111,7 +111,7 @@ int main(int argc, char *argv[]) {
}
}
- w.downloadData(Config::get(Config::LOCATIONS));
+ w.downloadData();
w.setTheme();
w.setWindowFlag(Qt::FramelessWindowHint, true);
w.resize(width, height);
diff --git a/src/session.h b/src/session.h
index 675aada..e926af8 100644
--- a/src/session.h
+++ b/src/session.h
@@ -17,6 +17,12 @@ enum SectionType {
class Session {
public:
+
+ enum EditType {
+ EDIT_TYPE_EDIT = 1,
+ EDIT_TYPE_COPY = 2,
+ };
+
virtual ~Session() {}
virtual bool isActive() const = 0;
@@ -46,6 +52,8 @@ class Session {
virtual int type() const = 0;
virtual SectionType section() const = 0;
virtual bool needsVtx() const { return false; }
+ virtual bool canEdit() const { return false; }
+ virtual int editModeTypes() const { return 0; }
virtual QVariant foregroundRole() const { return QVariant(); }
virtual bool operator<(const Session& s) const = 0;
diff --git a/src/ui/dialog.ui b/src/ui/dialog.ui
index b6d7822..0e195ea 100644
--- a/src/ui/dialog.ui
+++ b/src/ui/dialog.ui
@@ -63,7 +63,7 @@ margin-bottom:0px;}</string>
<string/>
</property>
<property name="pixmap">
- <pixmap resource="../images.qrc">:/title_l</pixmap>
+ <pixmap>:/title_l</pixmap>
</property>
</widget>
</item>
@@ -94,7 +94,7 @@ margin-bottom:0px;}</string>
<string/>
</property>
<property name="pixmap">
- <pixmap resource="../images.qrc">:/title_r</pixmap>
+ <pixmap>:/title_r</pixmap>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -133,8 +133,11 @@ margin-bottom:0px;}</string>
</property>
<property name="html">
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
-&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
+&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;meta charset=&quot;utf-8&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
+hr { height: 1px; border-width: 0; }
+li.unchecked::marker { content: &quot;\2610&quot;; }
+li.checked::marker { content: &quot;\2612&quot;; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans';&quot;&gt;Loading...&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
@@ -168,8 +171,11 @@ p, li { white-space: pre-wrap; }
</property>
<property name="html">
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
-&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
+&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;meta charset=&quot;utf-8&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
+hr { height: 1px; border-width: 0; }
+li.unchecked::marker { content: &quot;\2610&quot;; }
+li.checked::marker { content: &quot;\2612&quot;; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans';&quot;&gt;Loading...&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
@@ -213,7 +219,7 @@ p, li { white-space: pre-wrap; }
<string>Local</string>
</property>
<property name="icon">
- <iconset resource="../images.qrc">
+ <iconset>
<normaloff>:/linux</normaloff>:/linux</iconset>
</property>
<property name="iconSize">
@@ -255,7 +261,7 @@ p, li { white-space: pre-wrap; }
<string>All Classes</string>
</property>
<property name="icon">
- <iconset resource="../images.qrc">
+ <iconset>
<normaloff>:/vm-mix</normaloff>:/vm-mix</iconset>
</property>
<property name="iconSize">
@@ -499,8 +505,11 @@ border:1px solid #999;
</property>
<property name="html">
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
-&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
+&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;meta charset=&quot;utf-8&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
+hr { height: 1px; border-width: 0; }
+li.unchecked::marker { content: &quot;\2610&quot;; }
+li.checked::marker { content: &quot;\2612&quot;; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans';&quot;&gt;Click on an item on the left side for more information&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
@@ -539,13 +548,20 @@ p, li { white-space: pre-wrap; }
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
- <widget class="QCheckBox" name="chkAdminMode">
+ <widget class="QCheckBox" name="chkAdminEdit">
<property name="text">
<string>Edit VM</string>
</property>
</widget>
</item>
<item>
+ <widget class="QCheckBox" name="chkAdminCopy">
+ <property name="text">
+ <string>Copy VM</string>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QCheckBox" name="chkNoScreenSaver">
<property name="text">
<string>Disable ScreenSaver and Standby</string>
@@ -619,7 +635,6 @@ p, li { white-space: pre-wrap; }
<property name="font">
<font>
<pointsize>9</pointsize>
- <weight>50</weight>
<bold>false</bold>
</font>
</property>
@@ -670,8 +685,6 @@ p, li { white-space: pre-wrap; }
<header>src/vmtree.h</header>
</customwidget>
</customwidgets>
- <resources>
- <include location="../images.qrc"/>
- </resources>
+ <resources/>
<connections/>
</ui>
diff --git a/src/vsession.h b/src/vsession.h
index af01230..2641008 100644
--- a/src/vsession.h
+++ b/src/vsession.h
@@ -25,8 +25,12 @@ class VSession : public Session {
return getAttribute(QStringLiteral("for_location")).toInt() != 0;
}
- bool canEdit() const {
- return getAttribute(QStringLiteral("allow_edit")).toInt() != 0;
+ bool canEdit() const override {
+ return editModeTypes() != 0;
+ }
+
+ int editModeTypes() const override {
+ return getAttribute(QStringLiteral("allow_edit")).toInt();
}
QString virtualizer() const {
@@ -92,7 +96,7 @@ class VSession : public Session {
static QList<Session*> loadFromXmlDocument(const QDomDocument& doc);
protected:
- virtual QString checkCanRunInternal() const;
+ QString checkCanRunInternal() const;
private: