Skip to content

Commit

Permalink
libdeng2|libgui|Client|Server: Defining application metadata
Browse files Browse the repository at this point in the history
de::App now defines a method for setting all the application metadata in
one call without having to access Qt methods. Also, the Unix-style home
folder name can be defined from the application and is no longer
hardcoded to ".doomsday".
  • Loading branch information
skyjake committed Feb 18, 2014
1 parent 76f4aa6 commit 53ec5f6
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 15 deletions.
6 changes: 2 additions & 4 deletions doomsday/client/src/clientapp.cpp
Expand Up @@ -326,10 +326,8 @@ ClientApp::ClientApp(int &argc, char **argv)
QNetworkProxyFactory::setUseSystemConfiguration(true);

// Metadata.
setOrganizationDomain ("dengine.net");
setOrganizationName ("Deng Team");
setApplicationName ("Doomsday Engine");
setApplicationVersion (DOOMSDAY_VERSION_BASE);
setMetadata("Deng Team", "dengine.net", "Doomsday Engine", DOOMSDAY_VERSION_BASE);
setUnixHomeFolderName(".doomsday");

setTerminateFunc(handleLegacyCoreTerminate);

Expand Down
4 changes: 3 additions & 1 deletion doomsday/client/src/unix/dd_uinit.cpp
Expand Up @@ -25,6 +25,7 @@
#include <locale.h>

#include <de/c_wrapper.h>
#include <de/App>

#ifdef UNIX
# include "library.h"
Expand Down Expand Up @@ -63,7 +64,8 @@ static void determineGlobalPaths(application_t* app)
{
filename_t homePath;
directory_t* temp;
dd_snprintf(homePath, FILENAME_T_MAXLEN, "%s/.doomsday/runtime/", getenv("HOME"));
dd_snprintf(homePath, FILENAME_T_MAXLEN, "%s/%s/runtime/", getenv("HOME"),
DENG2_APP->unixHomeFolderName().toLatin1().constData());
temp = Dir_New(homePath);
Dir_mkpath(Dir_Path(temp));
app->usingHomeDir = Dir_SetCurrent(Dir_Path(temp));
Expand Down
25 changes: 25 additions & 0 deletions doomsday/libdeng2/include/de/core/app.h
Expand Up @@ -95,6 +95,31 @@ class DENG2_PUBLIC App : DENG2_OBSERVES(Clock, TimeChange)

virtual ~App();

/**
* Defines metadata about the application.
*
* @param appName Name of the application, as presented to humans.
* @param appVersion Version of the application.
* @param orgName Name of the author/organization.
* @param orgDomain Network domain of the author/organization.
*/
virtual void setMetadata(String const &orgName, String const &orgDomain,
String const &appName, String const &appVersion) = 0;

/**
* Sets the Unix-style home folder name. For instance, ".doomsday" could be used.
*
* @param name Name of the (usually hidden) user-specific home data folder.
*/
void setUnixHomeFolderName(String const &name);

String unixHomeFolderName() const;

/**
* Returns the home folder name without the possible dot in the beginning.
*/
String unixEtcFolderName() const;

/**
* Sets a callback to be called when an uncaught exception occurs.
*/
Expand Down
3 changes: 3 additions & 0 deletions doomsday/libdeng2/include/de/core/textapp.h
Expand Up @@ -46,6 +46,9 @@ class DENG2_PUBLIC TextApp : public QCoreApplication, public App,
public:
TextApp(int &argc, char **argv);

void setMetadata(String const &orgName, String const &orgDomain,
String const &appName, String const &appVersion);

bool notify(QObject *receiver, QEvent *event);

int execLoop();
Expand Down
31 changes: 28 additions & 3 deletions doomsday/libdeng2/src/core/app.cpp
Expand Up @@ -57,6 +57,7 @@ DENG2_PIMPL(App)

/// Path of the application executable.
NativePath appPath;
String unixHomeFolder;

NativePath cachedBasePath;
NativePath cachedPluginBinaryPath;
Expand Down Expand Up @@ -103,8 +104,13 @@ DENG2_PIMPL(App)
GameChangeScriptAudience scriptAudienceForGameChange;

Instance(Public *a, QStringList args)
: Base(a), cmdLine(args), persistentData(0), config(0),
currentGame(0), terminateFunc(0)
: Base(a)
, cmdLine(args)
, unixHomeFolder(".doomsday")
, persistentData(0)
, config(0)
, currentGame(0)
, terminateFunc(0)
{
singletonApp = a;
mainThread = QThread::currentThread();
Expand Down Expand Up @@ -263,6 +269,25 @@ App::~App()
singletonApp = 0;
}

void App::setUnixHomeFolderName(String const &name)
{
d->unixHomeFolder = name;
}

String App::unixHomeFolderName() const
{
return d->unixHomeFolder;
}

String App::unixEtcFolderName() const
{
if(d->unixHomeFolder.startsWith("."))
{
return d->unixHomeFolder.mid(1);
}
return d->unixHomeFolder;
}

void App::setTerminateFunc(void (*func)(char const *))
{
d->terminateFunc = func;
Expand Down Expand Up @@ -358,7 +383,7 @@ NativePath App::nativeHomePath()
nativeHome = nativeHome / "runtime";
#else // UNIX
NativePath nativeHome = QDir::homePath();
nativeHome = nativeHome / ".doomsday/runtime";
nativeHome = nativeHome / d->unixHomeFolder / "runtime";
#endif
return (d->cachedHomePath = nativeHome);
}
Expand Down
11 changes: 10 additions & 1 deletion doomsday/libdeng2/src/core/textapp.cpp
Expand Up @@ -42,6 +42,15 @@ TextApp::TextApp(int &argc, char **argv)
d(new Instance(this))
{}

void TextApp::setMetadata(String const &orgName, String const &orgDomain,
String const &appName, String const &appVersion)
{
setOrganizationName (orgName);
setOrganizationDomain(orgDomain);
setApplicationName (appName);
setApplicationVersion(appVersion);
}

bool TextApp::notify(QObject *receiver, QEvent *event)
{
try
Expand Down Expand Up @@ -83,7 +92,7 @@ Loop &TextApp::loop()

NativePath TextApp::appDataPath() const
{
return NativePath(QDir::homePath()) / ".doomsday";
return NativePath(QDir::homePath()) / unixHomeFolderName();
}

void TextApp::loopIteration()
Expand Down
5 changes: 3 additions & 2 deletions doomsday/libdeng2/src/core/unixinfo.cpp
Expand Up @@ -21,6 +21,7 @@

#include "de/UnixInfo"
#include "de/Info"
#include "de/App"
#include <QDir>

namespace de {
Expand All @@ -34,14 +35,14 @@ class Infos
public:
Infos(String fileName) : etcInfo(0), userInfo(0)
{
String fn = "/etc/doomsday/" + fileName;
String fn = String("/etc") / App::app().unixEtcFolderName() / fileName;
if(QFile::exists(fn))
{
etcInfo = new Info;
etcInfo->parseNativeFile(fn);
}

fn = QDir::homePath() + "/.doomsday/" + fileName;
fn = String(QDir::homePath()) / App::app().unixHomeFolderName() / fileName;
if(QFile::exists(fn))
{
userInfo = new Info;
Expand Down
3 changes: 3 additions & 0 deletions doomsday/libgui/include/de/gui/guiapp.h
Expand Up @@ -53,6 +53,9 @@ class LIBGUI_PUBLIC GuiApp : public QApplication, public App,
public:
GuiApp(int &argc, char **argv);

void setMetadata(String const &orgName, String const &orgDomain,
String const &appName, String const &appVersion);

bool notify(QObject *receiver, QEvent *event);

/**
Expand Down
9 changes: 9 additions & 0 deletions doomsday/libgui/src/guiapp.cpp
Expand Up @@ -44,6 +44,15 @@ GuiApp::GuiApp(int &argc, char **argv)
d(new Instance(this))
{}

void GuiApp::setMetadata(String const &orgName, String const &orgDomain,
String const &appName, String const &appVersion)
{
setOrganizationName (orgName);
setOrganizationDomain(orgDomain);
setApplicationName (appName);
setApplicationVersion(appVersion);
}

bool GuiApp::notify(QObject *receiver, QEvent *event)
{
try
Expand Down
6 changes: 2 additions & 4 deletions doomsday/server/src/serverapp.cpp
Expand Up @@ -103,10 +103,8 @@ ServerApp::ServerApp(int &argc, char **argv)
QNetworkProxyFactory::setUseSystemConfiguration(true);

// Metadata.
setOrganizationDomain ("dengine.net");
setOrganizationName ("Deng Team");
setApplicationName ("Doomsday Server");
setApplicationVersion (DOOMSDAY_VERSION_BASE);
setMetadata("Deng Team", "dengine.net", "Doomsday Server", DOOMSDAY_VERSION_BASE);
setUnixHomeFolderName(".doomsday");

setTerminateFunc(handleAppTerminate);

Expand Down

0 comments on commit 53ec5f6

Please sign in to comment.