#include <qapplication.h>
#include <qlayout.h>
#include <qtranslator.h>
#include <qtextcodec.h>
#include <qdir.h>
#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) |
|
||||||||||||
|
Definition at line 50 of file main.cpp. References 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, width, and XMLCONVERSION_PATH. 00051 {
00052 //create app
00053 QApplication a(argc, argv);
00054
00055 //----------------------------------------------
00056 //set material path
00057
00058 //PLATFORM_SPECIFIC_CODE
00059
00060 //if using mac os x material dir in bundle
00061 #if defined(Q_OS_MACX)
00062 CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
00063 CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle);
00064 MATERIAL_DIR = QString( CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding())) + "/Contents/Resources";
00065
00066 //Windows
00067 #elif defined(Q_OS_WIN)
00068 MATERIAL_DIR = a.applicationDirPath();
00069
00070 //Linux/FreeBSD - material path may be passed in or assumed to be the local path
00071 #else
00072 if( argc > 1 )
00073 {
00074 //user is running program from installed location (e.g. /usr/bin)
00075 //in which case we must assume material files are installed in the defined location
00076 if( QString(argv[1]).contains(QString(BIN_DIR)) != 0 )
00077 { MATERIAL_DIR = DATA_DIR; }
00078
00079 //if the above is not the case assume the user is running a non-installed copy of Album Shaper
00080 // (say right after compiling it, in which case the materials should be in the same location so
00081 //use application dir path directly
00082 else
00083 { MATERIAL_DIR = QString(argv[1]); }
00084 }
00085 //if the binary is run directly assume we're in the same directory as it and use the
00086 //current directory to load materials from
00087 else
00088 MATERIAL_DIR = "./";
00089 #endif
00090
00091 //----------------------------------------------
00092 //set image path
00093 IMAGE_PATH = MATERIAL_DIR + "/images/";
00094 //----------------------------------------------
00095 //set handbook path, attempt to use locale specific directory, otherwise fall back on english default
00096 HANDBOOK_PATH = MATERIAL_DIR + "/handbook_" + QTextCodec::locale() + "/";
00097 QDir handbookDir( HANDBOOK_PATH );
00098 if(!handbookDir.exists())
00099 HANDBOOK_PATH = MATERIAL_DIR + "/handbook/";
00100 //----------------------------------------------
00101 //set text path, attempt to use locale specific directory, otherwise fall back on english default
00102 TEXT_PATH = MATERIAL_DIR + "/text_" + QTextCodec::locale() + "/";
00103 QDir textDir( TEXT_PATH );
00104 if(!textDir.exists())
00105 TEXT_PATH = MATERIAL_DIR + "/text/";
00106 //----------------------------------------------
00107 //set themes path
00108 THEMES_PATH = MATERIAL_DIR + "/themes/";
00109 //----------------------------------------------
00110 //set xml conversion path
00111 XMLCONVERSION_PATH = MATERIAL_DIR + "/xmlConversion/";
00112 //----------------------------------------------
00113 //check that directory where user settings is stored exists, if not create
00114 //that directory at this time.
00115 if( !Configuration::constructSettingsDirectory() )
00116 {
00117 std::cout << "Error! Unable to make configurations directory!\n";
00118 return -1;
00119 }
00120 //----------------------------------------------
00121 //where temporary files can be placed
00122
00123 //PLATFORM_SPECIFIC_CODE
00124
00125 bool tempDirMade = true;
00126 QDir homeDir;
00127
00128 //Mac OS X
00129 #if defined(Q_OS_MACX)
00130 homeDir = QDir::homeDirPath();
00131 homeDir.cd("Library");
00132 homeDir.cd("Application Support");
00133 if(!homeDir.exists("Album Shaper"))
00134 { tempDirMade = homeDir.mkdir("Album Shaper"); }
00135 TEMP_DIR = QDir::convertSeparators( QDir::homeDirPath() + QString("/Library/Application Support/Album Shaper") );
00136
00137 //Windows
00138 #elif defined(Q_OS_WIN)
00139 QString folderLoc;
00140 if( !getWindowsFolderLocation(APPLICATION_DATA, folderLoc) )
00141 {
00142 std::cout << "Error! Unable to identify Application Data folder!\n";
00143 return -1;
00144 }
00145
00146 QDir applicationDataDir( folderLoc );
00147 if(!applicationDataDir.exists("Album Shaper"))
00148 { tempDirMade = applicationDataDir.mkdir("Album Shaper"); }
00149 TEMP_DIR = QDir::convertSeparators ( folderLoc + QString("/Album Shaper") );
00150
00151 //Unix/Linux/BSD
00152 #else
00153 homeDir = QDir::homeDirPath();
00154 if(!homeDir.exists(".albumShaper")) { tempDirMade = homeDir.mkdir(".albumShaper"); }
00155 TEMP_DIR = QDir::homeDirPath() + QString("/.albumShaper");
00156 #endif
00157
00158 //if unable to make configuration directory then abort
00159 if(!tempDirMade)
00160 {
00161 std::cout << "Error! Unable to make temp files directory!\n";
00162 return -1;
00163 }
00164 //----------------------------------------------
00165 //create translator for current locale and attempt to install
00166 QTranslator translator( 0 );
00167 translator.load( QString("AlbumShaper_") +
00168 // "sv",
00169 QTextCodec::locale(),
00170 MATERIAL_DIR + "/translations");
00171
00172 a.installTranslator( &translator );
00173
00174 //create main window and show
00175 Window window;
00176 a.setMainWidget( &window );
00177 //----------------------------------------------
00178 //set window size and position
00179 Configuration* config = window.getConfig();
00180 if( config->getBool( "layout", "restoreWindowPlacementSize") )
00181 {
00182 window.resize( config->getInt( "layout", "windowWidth" ),
00183 config->getInt( "layout", "windowHeight" ) );
00184
00185 window.move( config->getInt( "layout", "windowPosX" ),
00186 config->getInt( "layout", "windowPosY" ) );
00187 }
00188 else
00189 {
00190 QDesktopWidget *desktop = QApplication::desktop();
00191 int size = config->getInt( "layout", "defaultWindowSize" );
00192 int placement = config->getInt( "layout", "defaultWindowPlacement" );
00193
00194 QRect availRect = desktop->availableGeometry();
00195 int width = (size*availRect.width()) / 100;
00196 int height = (size*availRect.height()) / 100;
00197
00198 window.resize( width, height );
00199 width = window.frameGeometry().width();
00200 height = window.frameGeometry().height();
00201
00202 int x, y;
00203 //top left
00204 if(placement == TOP_LEFT)
00205 {
00206 x = availRect.left();
00207 y = availRect.top();
00208 }
00209 //top right
00210 else if(placement == TOP_RIGHT)
00211 {
00212 x = availRect.right() - width;
00213 y = availRect.top();
00214 }
00215 //bottom left
00216 else if(placement == BOTTOM_LEFT)
00217 {
00218 x = availRect.left();
00219 y = availRect.bottom() - height;
00220 }
00221 //bottom right
00222 else if(placement == BOTTOM_RIGHT)
00223 {
00224 x = availRect.right() - width;
00225 y = availRect.bottom() - height;
00226 }
00227 //center
00228 else
00229 {
00230 x = availRect.left() + (availRect.width() - width) / 2;
00231 y = availRect.top() + (availRect.height() - height) / 2;
00232 }
00233
00234 //place window
00235 window.move( x, y );
00236 }
00237 window.show();
00238
00239 //load cursors
00240 loadCursors();
00241
00242 //-----------------------------------
00243 //if this is a CVS build and cvsWarn set warn
00244 //user that application is potentially unstable!
00245 #ifdef CVS_CODE
00246 if( config->getBool ( "misc", "cvsWarn" ) )
00247 {
00248 AlertDialog alert( "Warning! Unstable build!",
00249 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!"),
00250 "alertIcons/warning.png", &window );
00251 alert.exec();
00252 }
00253 #endif
00254 //-----------------------------------
00255 //if this is the first time the program is being run then show welcome screen
00256 WelcomeWindow* welcome;
00257 if(config->getBool( "misc", "firstRun" ) )
00258 {
00259 welcome = new WelcomeWindow();
00260 welcome->show();
00261 centerWindow(welcome);
00262 config->setBool( "misc", "firstRun", false );
00263 }
00264 //-----------------------------------
00265 return a.exec();
00266 }
|
1.3.9.1