package: x2goclient
priority: wishlist
tags: patch

This is a proposal patch in order to add support for randomly picked backround 
image from a directory.

I did this because I'd like to have my TCEs load different pictures each time 
they're on a bit like the welcome picture on Windows 10.
This patch only check if the --background parameter is a directory and if so, 
pick randomly a SVG file from it.


Regards,
Walid Moghrabi

TRAVAUX.COM
BAT I - PARC CEZANNE 2 290 AVENUE GALILEE - CS 80403
13591 AIX EN PROVENCE CEDEX 3

---
DISCLAIMER: This e-mail is private and confidential and may contain proprietary 
or legally privileged information. It is for the intended recipient only. If 
you have received this email in error, please notify the author by replying to 
it and then destroy it. If you are not the intended recipient you must not use, 
disclose, distribute, copy, print or rely on this e-mail or any attachment. 
Thank you
diff --git a/man/man1/x2goclient.1 b/man/man1/x2goclient.1
index d90a888..c9e1531 100644
--- a/man/man1/x2goclient.1
+++ b/man/man1/x2goclient.1
@@ -94,9 +94,10 @@ The support information is provided via a simple HTML file. Example:
 .RE
 .\}
 .TP
-\*(T<\fB\-\-background=<svg-file>\fR\*(T>
+\*(T<\fB\-\-background=<svg-file|dir>\fR\*(T>
 Use a custom/branded background image (SVG format) for X2Go Client's main window (i.e. replace the blue gradient area
 in X2Go Client by some background of your own (business/workgroup/project).
+If a directory is given, will randomly pick a SVG file inside.
 .TP
 \*(T<\fB\-\-branding=<svg-file>\fR\*(T>
 Use a custom icon (SVG format) for additional branding to replace the default in the lower left corner of X2Go Client's main window.
diff --git a/src/help.cpp b/src/help.cpp
index e3cb1de..05c708f 100644
--- a/src/help.cpp
+++ b/src/help.cpp
@@ -154,7 +154,7 @@ help::params_t help::build_params () {
   ADD_OPT ("--broker-ssh-key=<path to key>", QT_TRANSLATE_NOOP ("Help", "Sets the path to an SSH key to use for authentication against an SSH session broker. The client's behavior is undefined if this flag is used for non-SSH session brokers."));
   ADD_OPT ("--broker-autologin", QT_TRANSLATE_NOOP ("Help", "Enables the use of the default SSH key or SSH agent for authentication against an SSH session broker. The client's behavior is undefined if this flag is used for non-SSH session brokers."));
   ADD_OPT ("--broker-noauth", QT_TRANSLATE_NOOP ("Help", "Does not ask for user credentials during session broker authentication. This can be useful if you are using an HTTP(S) session broker without authentication. If you run an HTTP(S) server without authentication, but with user-specific profiles, then put the user name into the broker URL (refer to --broker-url.) The user name then will be extracted from the broker URL and be sent to the session broker. The client's behavior is undefined if this flag is used for non-HTTP(S) session brokers."));
-  ADD_OPT ("--background=<svg-file>", QT_TRANSLATE_NOOP ("Help", "Use a custom/branded background image (SVG format) for X2Go Client's main window."));
+  ADD_OPT ("--background=<svg-file|dir>", QT_TRANSLATE_NOOP ("Help", "Use a custom/branded background image (SVG format) for X2Go Client's main window. If directory is given, will randomly pick a SVG file inside."));
   ADD_OPT ("--branding=<svg-file>", QT_TRANSLATE_NOOP ("Help", "Use a custom icon (SVG format) for additional branding to replace the default in the lower left corner of X2Go Client's main window."));
 
 # undef NEWLINE
diff --git a/src/onmainwindow.cpp b/src/onmainwindow.cpp
index 5dd3906..8ac3f68 100644
--- a/src/onmainwindow.cpp
+++ b/src/onmainwindow.cpp
@@ -342,10 +342,26 @@ ONMainWindow::ONMainWindow ( QWidget *parent ) :QMainWindow ( parent )
 
 
 #ifndef Q_WS_HILDON
+
+	// See if BGFile is a directory and retrieve a SVG file randomly from within
+	QFileInfo BGDir(BGFile);
+	if (BGDir.isDir())
+	{
+		QDirIterator it(BGFile, QStringList() << "*.svg", QDir::Files, QDirIterator::NoIteratorFlags);
+		QStringList fileList;
+		while (it.hasNext())
+			fileList << it.next();
+
+		qsrand(QTime::currentTime().msec());
+		int max=fileList.size();
+		int random_selector=(static_cast<int>(1 + (static_cast<float>(qrand()) / RAND_MAX * max))) - 1;
+		BGFile=fileList.at(random_selector);
+	}
+
     if (BGFile.size())
-        bgFrame=new SVGFrame ( ( QString ) BGFile,true,fr );
+   	    bgFrame=new SVGFrame ( ( QString ) BGFile,true,fr );
     else
-        bgFrame=new SVGFrame ( ( QString ) ":/img/svg/bg.svg",true,fr );
+   	    bgFrame=new SVGFrame ( ( QString ) ":/img/svg/bg.svg",true,fr );
 #else
     bgFrame=new SVGFrame ( ( QString ) ":/img/svg/bg_hildon.svg",true,fr );
 #endif
diff --git a/src/onmainwindow.h b/src/onmainwindow.h
index 37b454c..88f7417 100644
--- a/src/onmainwindow.h
+++ b/src/onmainwindow.h
@@ -46,6 +46,7 @@
 #include <QProcessEnvironment>
 #include "sshmasterconnection.h"
 #include "non_modal_messagebox.h"
+#include <QDirIterator>
 
 
 #ifdef Q_OS_WIN
_______________________________________________
x2go-dev mailing list
[email protected]
http://lists.x2go.org/listinfo/x2go-dev

Reply via email to