AlbumShaper  1.0a3
Functions
main.cpp File Reference
#include <qapplication.h>
#include <qlayout.h>
#include <qtranslator.h>
#include <qtextcodec.h>
#include <qdir.h>
#include <QDesktopWidget>
#include <iostream>
#include "gui/cursors.h"
#include "gui/window.h"
#include "gui/dialogs/alertDialog.h"
#include "gui/welcomeWindow/welcomeWindow.h"
#include "backend/tools/guiTools.h"
#include "config.h"
#include "configuration/configuration.h"
#include "configuration/layoutSettingsWidget.h"
#include "backend/tools/fileTools.h"
Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

§ main()

int main ( int  argc,
char **  argv 
)

Definition at line 51 of file main.cpp.

References BOTTOM_LEFT, BOTTOM_RIGHT, centerWindow(), Configuration::constructSettingsDirectory(), Configuration::getBool(), Window::getConfig(), Configuration::getInt(), HANDBOOK_PATH, height, IMAGE_PATH, loadCursors(), MATERIAL_DIR, Configuration::setBool(), TEMP_DIR, TEXT_PATH, THEMES_PATH, TOP_LEFT, TOP_RIGHT, width, and XMLCONVERSION_PATH.

52 {
53  //create app
54  QApplication a(argc, argv);
55 
56  //----------------------------------------------
57  //set material path
58 
59  //PLATFORM_SPECIFIC_CODE
60 
61  //if using mac os x material dir in bundle
62  #if defined(Q_OS_MACX)
63  CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
64  CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle);
65  MATERIAL_DIR = QString( CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding())) + "/Contents/Resources";
66 
67  //Windows
68  #elif defined(Q_OS_WIN)
69  MATERIAL_DIR = a.applicationDirPath();
70 
71  //Linux/FreeBSD - material path may be passed in or assumed to be the local path
72  #else
73  if( argc > 1 )
74  {
75  //user is running program from installed location (e.g. /usr/bin)
76  //in which case we must assume material files are installed in the defined location
77  if( QString(argv[1]).contains(QString(BIN_DIR)) != 0 )
78  { MATERIAL_DIR = DATA_DIR; }
79 
80  //if the above is not the case assume the user is running a non-installed copy of Album Shaper
81  // (say right after compiling it, in which case the materials should be in the same location so
82  //use application dir path directly
83  else
84  { MATERIAL_DIR = QString(argv[1]); }
85  }
86  //if the binary is run directly assume we're in the same directory as it and use the
87  //current directory to load materials from
88  else
89  MATERIAL_DIR = "./";
90  #endif
91 
92  //----------------------------------------------
93  //set image path
94  IMAGE_PATH = MATERIAL_DIR + "/images/";
95  //----------------------------------------------
96  //set handbook path, attempt to use locale specific directory, otherwise fall back on english default
97  HANDBOOK_PATH = MATERIAL_DIR + "/handbook_" + QTextCodec::locale() + "/";
98  QDir handbookDir( HANDBOOK_PATH );
99  if(!handbookDir.exists())
100  HANDBOOK_PATH = MATERIAL_DIR + "/handbook/";
101  //----------------------------------------------
102  //set text path, attempt to use locale specific directory, otherwise fall back on english default
103  TEXT_PATH = MATERIAL_DIR + "/text_" + QTextCodec::locale() + "/";
104  QDir textDir( TEXT_PATH );
105  if(!textDir.exists())
106  TEXT_PATH = MATERIAL_DIR + "/text/";
107  //----------------------------------------------
108  //set themes path
109  THEMES_PATH = MATERIAL_DIR + "/themes/";
110  //----------------------------------------------
111  //set xml conversion path
112  XMLCONVERSION_PATH = MATERIAL_DIR + "/xmlConversion/";
113  //----------------------------------------------
114  //check that directory where user settings is stored exists, if not create
115  //that directory at this time.
117  {
118  std::cout << "Error! Unable to make configurations directory!\n";
119  return -1;
120  }
121  //----------------------------------------------
122  //where temporary files can be placed
123 
124  //PLATFORM_SPECIFIC_CODE
125 
126  bool tempDirMade = true;
127  QDir homeDir;
128 
129  //Mac OS X
130  #if defined(Q_OS_MACX)
131  homeDir = QDir::homeDirPath();
132  homeDir.cd("Library");
133  homeDir.cd("Application Support");
134  if(!homeDir.exists("Album Shaper"))
135  { tempDirMade = homeDir.mkdir("Album Shaper"); }
136  TEMP_DIR = QDir::convertSeparators( QDir::homeDirPath() + QString("/Library/Application Support/Album Shaper") );
137 
138  //Windows
139  #elif defined(Q_OS_WIN)
140  QString folderLoc;
141  if( !getWindowsFolderLocation(APPLICATION_DATA, folderLoc) )
142  {
143  std::cout << "Error! Unable to identify Application Data folder!\n";
144  return -1;
145  }
146 
147  QDir applicationDataDir( folderLoc );
148  if(!applicationDataDir.exists("Album Shaper"))
149  { tempDirMade = applicationDataDir.mkdir("Album Shaper"); }
150  TEMP_DIR = QDir::convertSeparators ( folderLoc + QString("/Album Shaper") );
151 
152  //Unix/Linux/BSD
153  #else
154  homeDir = QDir::homeDirPath();
155  if(!homeDir.exists(".albumShaper")) { tempDirMade = homeDir.mkdir(".albumShaper"); }
156  TEMP_DIR = QDir::homeDirPath() + QString("/.albumShaper");
157  #endif
158 
159  //if unable to make configuration directory then abort
160  if(!tempDirMade)
161  {
162  std::cout << "Error! Unable to make temp files directory!\n";
163  return -1;
164  }
165  //----------------------------------------------
166  //create translator for current locale and attempt to install
167  QTranslator translator( 0 );
168  translator.load( QString("AlbumShaper_") +
169 // "sv",
170  QTextCodec::locale(),
171  MATERIAL_DIR + "/translations");
172 
173  a.installTranslator( &translator );
174 
175  //create main window and show
176  Window window;
177  a.setMainWidget( &window );
178  //----------------------------------------------
179  //set window size and position
180  Configuration* config = window.getConfig();
181  if( config->getBool( "layout", "restoreWindowPlacementSize") )
182  {
183  window.resize( config->getInt( "layout", "windowWidth" ),
184  config->getInt( "layout", "windowHeight" ) );
185 
186  window.move( config->getInt( "layout", "windowPosX" ),
187  config->getInt( "layout", "windowPosY" ) );
188  }
189  else
190  {
191  QDesktopWidget *desktop = QApplication::desktop();
192  int size = config->getInt( "layout", "defaultWindowSize" );
193  int placement = config->getInt( "layout", "defaultWindowPlacement" );
194 
195  QRect availRect = desktop->availableGeometry();
196  int width = (size*availRect.width()) / 100;
197  int height = (size*availRect.height()) / 100;
198 
199  window.resize( width, height );
200  width = window.frameGeometry().width();
201  height = window.frameGeometry().height();
202 
203  int x, y;
204  //top left
205  if(placement == TOP_LEFT)
206  {
207  x = availRect.left();
208  y = availRect.top();
209  }
210  //top right
211  else if(placement == TOP_RIGHT)
212  {
213  x = availRect.right() - width;
214  y = availRect.top();
215  }
216  //bottom left
217  else if(placement == BOTTOM_LEFT)
218  {
219  x = availRect.left();
220  y = availRect.bottom() - height;
221  }
222  //bottom right
223  else if(placement == BOTTOM_RIGHT)
224  {
225  x = availRect.right() - width;
226  y = availRect.bottom() - height;
227  }
228  //center
229  else
230  {
231  x = availRect.left() + (availRect.width() - width) / 2;
232  y = availRect.top() + (availRect.height() - height) / 2;
233  }
234 
235  //place window
236  window.move( x, y );
237  }
238  window.show();
239 
240  //load cursors
241  loadCursors();
242 
243  //-----------------------------------
244  //if this is a CVS build and cvsWarn set warn
245  //user that application is potentially unstable!
246  #ifdef CVS_CODE
247  if( config->getBool ( "misc", "cvsWarn" ) )
248  {
249  AlertDialog alert( "Warning! Unstable build!",
250  QString("Warning! You are running a potentially unstable (CVS) build of Album Shaper! It is strongly suggested you only use this copy for testing and evaluation purposes. Data loss may occur!"),
251  "alertIcons/warning.png", &window );
252  alert.exec();
253  }
254  #endif
255  //-----------------------------------
256  //if this is the first time the program is being run then show welcome screen
257  WelcomeWindow* welcome;
258  if(config->getBool( "misc", "firstRun" ) )
259  {
260  welcome = new WelcomeWindow();
261  welcome->show();
262  centerWindow(welcome);
263  config->setBool( "misc", "firstRun", false );
264  }
265  //-----------------------------------
266  return a.exec();
267 }
QString TEMP_DIR
Definition: config.cpp:23
A configurable alert dialog that displays an alert/error message.
Definition: alertDialog.h:36
void centerWindow(QWidget *window)
Definition: guiTools.cpp:26
Top level widget, encapsulates the title widget, the layout widget, and the toolbar widget...
Definition: window.h:39
bool getBool(QString group, QString key)
Fetch bool setting.
void setBool(QString group, QString key, bool val)
Set bool setting.
QString TEXT_PATH
Definition: config.cpp:20
QString IMAGE_PATH
Definition: config.cpp:18
Configuration * getConfig()
get setting object
Definition: window.cpp:235
QString MATERIAL_DIR
Definition: config.cpp:17
int getInt(QString group, QString key)
Fetch int setting.
int width
Definition: blur.cpp:79
QString HANDBOOK_PATH
Definition: config.cpp:19
QString XMLCONVERSION_PATH
Definition: config.cpp:22
#define TOP_LEFT
static bool constructSettingsDirectory()
Constructs any necessary directories for loading and saving user settings, returns false if unsuccess...
void loadCursors()
Definition: cursors.cpp:34
Configuration object manages all user-specific application settings.
Definition: configuration.h:24
#define BOTTOM_LEFT
#define BOTTOM_RIGHT
#define TOP_RIGHT
QString THEMES_PATH
Definition: config.cpp:21
int height
Definition: blur.cpp:79