From f45aa5ce9ee21679abbe263ec2df7f0254331f4b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Sat, 24 Apr 2010 19:40:18 +0200
Subject: Add About dialog to Slimber/Qt.


diff --git a/Slimber/Qt/QtAboutDialog.cpp b/Slimber/Qt/QtAboutDialog.cpp
new file mode 100644
index 0000000..9b4e821
--- /dev/null
+++ b/Slimber/Qt/QtAboutDialog.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include "Slimber/Qt/QtAboutDialog.h"
+
+#include <QCoreApplication>
+#include <QVBoxLayout>
+#include <QLabel>
+#include <QPixmap>
+
+QtAboutDialog::QtAboutDialog() {
+	setAttribute(Qt::WA_DeleteOnClose);
+	setWindowTitle("About Slimber");
+
+	QVBoxLayout* layout = new QVBoxLayout(this);
+	
+	QLabel* iconLabel = new QLabel(this);
+	iconLabel->setPixmap(QPixmap(":/icons/Icon-128.png"));
+	iconLabel->setAlignment(Qt::AlignHCenter);
+	layout->addWidget(iconLabel);
+	
+	QLabel* appNameLabel = new QLabel("<center><font size='+1'><b>" + QCoreApplication::applicationName() + "</b></font></center>", this);
+	layout->addWidget(appNameLabel);
+	
+	QLabel* versionLabel = new QLabel(QString("<center><font size='-1'>Version ") + QCoreApplication::applicationVersion() + "</font></center>", this);
+	layout->addWidget(versionLabel);
+	QString buildString = QString("<center><font size='-1'>Built with: Qt version ") + QT_VERSION_STR;
+	buildString += QString("<br/>Running with Qt version ") + qVersion();
+	buildString += "</font></center>";
+	QLabel* buildLabel = new QLabel(buildString, this);
+	layout->addWidget(buildLabel);
+
+	setFixedSize(minimumSizeHint());
+}
diff --git a/Slimber/Qt/QtAboutDialog.h b/Slimber/Qt/QtAboutDialog.h
new file mode 100644
index 0000000..9e139da
--- /dev/null
+++ b/Slimber/Qt/QtAboutDialog.h
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <QDialog>
+
+class QtAboutDialog : public QDialog {
+	public:
+		QtAboutDialog();	
+};
diff --git a/Slimber/Qt/QtMenulet.h b/Slimber/Qt/QtMenulet.h
index 19458b3..08bae0c 100644
--- a/Slimber/Qt/QtMenulet.h
+++ b/Slimber/Qt/QtMenulet.h
@@ -12,8 +12,10 @@
 #include <QSystemTrayIcon>
 #include <QObject>
 #include <QPixmap>
+#include <QPointer>
 
 #include "Slimber/Menulet.h"
+#include "Slimber/Qt/QtAboutDialog.h"
 
 class QtMenulet : public QObject, public Menulet {
 		Q_OBJECT
@@ -33,7 +35,7 @@ class QtMenulet : public QObject, public Menulet {
 		}
 
 		void addAboutItem() {
-			menu.addAction("About");
+			menu.addAction("About", this, SLOT(showAboutDialog()));
 		}
 
 		void addRestartItem() {
@@ -59,6 +61,14 @@ class QtMenulet : public QObject, public Menulet {
 
 	private slots:
 		void showAboutDialog() {
+			if (aboutDialog) {
+				aboutDialog->raise();
+				aboutDialog->activateWindow();
+			}
+			else {
+				aboutDialog = new QtAboutDialog();
+				aboutDialog->show();
+			}
 		}
 
 		void restart() {
@@ -68,4 +78,5 @@ class QtMenulet : public QObject, public Menulet {
 	private:
 		QMenu menu;
 		QSystemTrayIcon trayIcon;
+		QPointer<QtAboutDialog> aboutDialog;
 };
diff --git a/Slimber/Qt/SConscript b/Slimber/Qt/SConscript
index 5e28b58..6fced8b 100644
--- a/Slimber/Qt/SConscript
+++ b/Slimber/Qt/SConscript
@@ -22,9 +22,12 @@ if env["PLATFORM"] == "win32" :
 	myenv.Append(LINKFLAGS = ["/SUBSYSTEM:WINDOWS"])
 	myenv.Append(LIBS = "qtmain")
 
+myenv.BuildVersion("BuildVersion.h", version = env["SLIMBER_VERSION"])
+
 sources = [
 		"main.cpp", 
 		"QtMenulet.cpp",
+		"QtAboutDialog.cpp",
 		myenv.Qrc("Slimber.qrc"),
 	]
 
diff --git a/Slimber/Qt/Slimber.qrc b/Slimber/Qt/Slimber.qrc
index 6cc21ff..26b5985 100644
--- a/Slimber/Qt/Slimber.qrc
+++ b/Slimber/Qt/Slimber.qrc
@@ -5,5 +5,6 @@
 		<file alias="icons/Online.png">../Resources/Online.png</file>
 		<file alias="icons/UsersOffline.png">../Resources/UsersOffline.png</file>
 		<file alias="icons/UsersOnline.png">../Resources/UsersOnline.png</file>
+		<file alias="icons/Icon-128.png">../Resources/Icon-128.png</file>
 	</qresource>
 </RCC>
diff --git a/Slimber/Qt/main.cpp b/Slimber/Qt/main.cpp
index 6016945..6c6ea26 100644
--- a/Slimber/Qt/main.cpp
+++ b/Slimber/Qt/main.cpp
@@ -5,22 +5,29 @@
  */
 
 #include <QApplication>
+#include <QCoreApplication>
 #include <QSystemTrayIcon>
 #include <QMessageBox>
 
 #include "QtMenulet.h"
 #include "Slimber/MainController.h"
 #include "Swiften/EventLoop/Qt/QtEventLoop.h"
+#include "Slimber/Qt/BuildVersion.h"
 
 int main(int argc, char* argv[]) {
 	QApplication app(argc, argv);
 	QtEventLoop eventLoop;
 
+	QCoreApplication::setApplicationName("Slimber");
+	QCoreApplication::setApplicationVersion(QString(buildVersion));
+
 	if (!QSystemTrayIcon::isSystemTrayAvailable()) {
 QMessageBox::critical(0, QObject::tr("Systray"), QObject::tr("No system tray"));
 		return 1;
 	}
 
+	app.setQuitOnLastWindowClosed(false);
+
 	QtMenulet menulet;
 	MainController controller(&menulet);
 
diff --git a/Slimber/SConscript b/Slimber/SConscript
index 2d1d33b..9a84c17 100644
--- a/Slimber/SConscript
+++ b/Slimber/SConscript
@@ -1,3 +1,5 @@
+import datetime 
+
 Import("env")
 
 env["BUILD_SLIMBER"] = True
@@ -41,6 +43,9 @@ if "Slimber" in env["PROJECTS"] :
 				"Menulet.cpp"
 			])
 
+	
+		env["SLIMBER_VERSION"] = "0.9.9." + datetime.date.today().strftime("%Y%m%d")
+
 		env.Append(UNITTEST_SOURCES = [
 				File("UnitTest/LinkLocalPresenceManagerTest.cpp"),
 				File("UnitTest/MenuletControllerTest.cpp")
-- 
cgit v0.10.2-6-g49f6