Fork me on GitHub
2.15.20
FGx
A cross-platform launcher for FlightGear
xsettings.cpp
Go to the documentation of this file.
1 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-
2 // FGx FlightGear Launcher // xsettings.cpp
3 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-
4 // (c) 2010-2012
5 // Yves Sablonier, Pete Morgan
6 // Geoff McLane
7 // GNU GPLv2, see main.cpp and shipped licence.txt for further information
8 
9 
10 #include <QDir>
11 #include <QVariant>
12 
13 #include <QDesktopServices>
14 #include <QWidget>
15 
16 #include "xsettings.h"
17 #include "utilities/utilities.h"
18 
19 
20 /*! \class XSettings
21  * \brief The XSettings is an extended QSetttings, but also includes most to the FGx configuration.
22  *
23  * The general idea of the class is to provide one central place to access settings. It is
24  * for this reason that methods are created to hide some of the completities, such as aircraft_path().
25  *
26  */
27 
28 
30  QSettings(parent)
31 {
32 }
33 
34 //===========================================================================
35 // Style
36 //===========================================================================
37 /** \brief return the currently selected style or the default
38  */
40  return value("gui_style", style_default()).toString();
41 }
42 
44  return "cleanlooks";
45 
46 }
47 
48 //===========================================================================
49 //** fgx Install path
50 //===========================================================================
52  return QDir::currentPath().append("/fgx.app/Contents/MacOS");
53 }
54 
55 //===========================================================================
56 //** Save/Restore Splitter
57 //===========================================================================
58 /** \brief Saves a splitters dimensions
59  *
60  * The `settings_namespace` property needs to be set
61  *
62  * @todo check for settings_namespace
63  * @bug no namespace problem
64  */
65 void XSettings::saveSplitter(QSplitter *splitter){
66  QString key = splitter->property("settings_namespace").toString();
67  QByteArray ba = splitter->saveState();
68  outLog("saveSplitter: Key="+key+", values "+ba.toHex());
69  setValue( key, QVariant(ba) );
70 }
71 
72 /** \brief Restores a splitters dimensions
73  * @todo check for settings_namespace
74  * @bug no namespace problem
75  */
76 void XSettings::restoreSplitter(QSplitter *splitter){
77  QString key = splitter->property("settings_namespace").toString();
78  QByteArray ba = value(key).toByteArray();
79  outLog("saveSplitter: Key="+key+", values "+ba.toHex());
80  splitter->restoreState( ba );
81 }
82 
83 
84 //===========================================================================
85 //** Save/Restore Window
86 //===========================================================================
87 /** \brief Saves a window's size and position
88  *
89  */
91  QString key = _windowName(widget);
92  QByteArray ba = widget->saveGeometry();
93  outLog("saveWindow: Key="+key+", values "+ba.toHex());
94  setValue( key, QVariant(ba) );
95 }
96 /** \brief Restores a size window position
97  *
98  * @todo check screensize
99  * @bug monitor could be offscreen
100  */
102  QString key = _windowName(widget);
103  QByteArray ba = value(_windowName(widget)).toByteArray();
104  outLog("restoreWindow: Key="+key+", values "+ba.toHex());
105 
106  // Set fixed size to 900,700 of all windows for first startup
107  if (ba != "") {
108  widget->restoreGeometry(ba);
109  } else {
110  if (widget->accessibleName() == "launcherWindow") {
111  widget->resize(900,700);
112  }
113  }
114 
115  // We need to check here window is nto offsreen,
116  // eg a dual monitor previous and now no dual so screen is restored off screen
117  //QDesktopSccreen dimensions vs postion
118 }
119 
120 /** \brief Extracts the `settings_namespace` property */
122  QString key_name = "window/";
123  key_name.append(widget->property("settings_namespace").toString());
124  key_name.append("/geometry");
125  return key_name;
126 }
127 
128 
129 /** \brief The "Special Developer Flag"
130  *
131  * This is one of those magic workaround functions to detect if in development mode.
132  * The functions detects if the file "DEV_MODE.txt" exists in the current directory.
133  * eg in fgx/src/DEV_MODE.txt
134  * The precense of this file make a few things happen.. such as redirecting login to shell
135  * Reading stuff from files in stead of resources etc..
136  * \return developer mode enabled
137  */
139  QString curr = XSettings::fgx_current_dir().append("/DEV_MODE.txt");
140  return QFile::exists(curr);
141 }
142 
143 /** \brief this should be used, yves ?
144  */
146  return QDir::current().absolutePath();
147 }
148 
149 /** \brief shortcut to cache directory
150  *
151  */
153  return QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
154 }
static bool dev_mode()
The "Special Developer Flag".
Definition: xsettings.cpp:138
static QString fgx_current_dir()
this should be used, yves ?
Definition: xsettings.cpp:145
QString style_current()
return the currently selected style or the default
Definition: xsettings.cpp:39
QString _windowName(QWidget *widget)
Extracts the settings_namespace property.
Definition: xsettings.cpp:121
void saveWindow(QWidget *widget)
Saves a window's size and position.
Definition: xsettings.cpp:90
void saveSplitter(QSplitter *splitter)
Saves a splitters dimensions.
Definition: xsettings.cpp:65
QString style_default()
Definition: xsettings.cpp:43
void restoreWindow(QWidget *widget)
Restores a size window position.
Definition: xsettings.cpp:101
XSettings(QObject *parent=0)
Definition: xsettings.cpp:29
void restoreSplitter(QSplitter *splitter)
Restores a splitters dimensions.
Definition: xsettings.cpp:76
QString fgx_path()
Definition: xsettings.cpp:51
static QString cache_dir()
shortcut to cache directory
Definition: xsettings.cpp:152