#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 //otherwise material path can be passed in or assumed to be the local path 00071 #else 00072 if(argc > 1) 00073 MATERIAL_DIR = QString(argv[1]).replace("/usr/bin", "/usr/share/albumshaper"); 00074 else 00075 MATERIAL_DIR = "./"; 00076 #endif 00077 //---------------------------------------------- 00078 //set image path 00079 IMAGE_PATH = MATERIAL_DIR + "/images/"; 00080 //---------------------------------------------- 00081 //set handbook path, attempt to use locale specific directory, otherwise fall back on english default 00082 HANDBOOK_PATH = MATERIAL_DIR + "/handbook_" + QTextCodec::locale() + "/"; 00083 QDir handbookDir( HANDBOOK_PATH ); 00084 if(!handbookDir.exists()) 00085 HANDBOOK_PATH = MATERIAL_DIR + "/handbook/"; 00086 //---------------------------------------------- 00087 //set text path, attempt to use locale specific directory, otherwise fall back on english default 00088 TEXT_PATH = MATERIAL_DIR + "/text_" + QTextCodec::locale() + "/"; 00089 QDir textDir( TEXT_PATH ); 00090 if(!textDir.exists()) 00091 TEXT_PATH = MATERIAL_DIR + "/text/"; 00092 //---------------------------------------------- 00093 //set themes path 00094 THEMES_PATH = MATERIAL_DIR + "/themes/"; 00095 //---------------------------------------------- 00096 //set xml conversion path 00097 XMLCONVERSION_PATH = MATERIAL_DIR + "/xmlConversion/"; 00098 //---------------------------------------------- 00099 //check that directory where user settings is stored exists, if not create 00100 //that directory at this time. 00101 if( !Configuration::constructSettingsDirectory() ) 00102 { 00103 std::cout << "Error! Unable to make configurations directory!\n"; 00104 return -1; 00105 } 00106 //---------------------------------------------- 00107 //where temporary files can be placed 00108 00109 //PLATFORM_SPECIFIC_CODE 00110 00111 bool tempDirMade = true; 00112 QDir homeDir; 00113 00114 //Mac OS X 00115 #if defined(Q_OS_MACX) 00116 homeDir = QDir::homeDirPath(); 00117 homeDir.cd("Library"); 00118 homeDir.cd("Application Support"); 00119 if(!homeDir.exists("Album Shaper")) 00120 { tempDirMade = homeDir.mkdir("Album Shaper"); } 00121 TEMP_DIR = QDir::convertSeparators( QDir::homeDirPath() + QString("/Library/Application Support/Album Shaper") ); 00122 00123 //Windows 00124 #elif defined(Q_OS_WIN) 00125 QString folderLoc; 00126 if( !getWindowsFolderLocation(APPLICATION_DATA, folderLoc) ) 00127 { 00128 std::cout << "Error! Unable to identify Application Data folder!\n"; 00129 return -1; 00130 } 00131 00132 QDir applicationDataDir( folderLoc ); 00133 if(!applicationDataDir.exists("Album Shaper")) 00134 { tempDirMade = applicationDataDir.mkdir("Album Shaper"); } 00135 TEMP_DIR = QDir::convertSeparators ( folderLoc + QString("/Album Shaper") ); 00136 00137 //Unix/Linux/BSD 00138 #else 00139 homeDir = QDir::homeDirPath(); 00140 if(!homeDir.exists(".albumShaper")) { tempDirMade = homeDir.mkdir(".albumShaper"); } 00141 TEMP_DIR = QDir::homeDirPath() + QString("/.albumShaper"); 00142 #endif 00143 00144 //if unable to make configuration directory then abort 00145 if(!tempDirMade) 00146 { 00147 std::cout << "Error! Unable to make temp files directory!\n"; 00148 return -1; 00149 } 00150 //---------------------------------------------- 00151 //create translator for current locale and attempt to install 00152 QTranslator translator( 0 ); 00153 translator.load( QString("AlbumShaper_") + QTextCodec::locale(), MATERIAL_DIR + "/translations"); 00154 a.installTranslator( &translator ); 00155 00156 //create main window and show 00157 Window window; 00158 a.setMainWidget( &window ); 00159 //---------------------------------------------- 00160 //set window size and position 00161 Configuration* config = window.getConfig(); 00162 if( config->getBool( "layout", "restoreWindowPlacementSize") ) 00163 { 00164 window.resize( config->getInt( "layout", "windowWidth" ), 00165 config->getInt( "layout", "windowHeight" ) ); 00166 00167 window.move( config->getInt( "layout", "windowPosX" ), 00168 config->getInt( "layout", "windowPosY" ) ); 00169 } 00170 else 00171 { 00172 QDesktopWidget *desktop = QApplication::desktop(); 00173 int size = config->getInt( "layout", "defaultWindowSize" ); 00174 int placement = config->getInt( "layout", "defaultWindowPlacement" ); 00175 00176 QRect availRect = desktop->availableGeometry(); 00177 int width = (size*availRect.width()) / 100; 00178 int height = (size*availRect.height()) / 100; 00179 00180 window.resize( width, height ); 00181 width = window.frameGeometry().width(); 00182 height = window.frameGeometry().height(); 00183 00184 int x, y; 00185 //top left 00186 if(placement == TOP_LEFT) 00187 { 00188 x = availRect.left(); 00189 y = availRect.top(); 00190 } 00191 //top right 00192 else if(placement == TOP_RIGHT) 00193 { 00194 x = availRect.right() - width; 00195 y = availRect.top(); 00196 } 00197 //bottom left 00198 else if(placement == BOTTOM_LEFT) 00199 { 00200 x = availRect.left(); 00201 y = availRect.bottom() - height; 00202 } 00203 //bottom right 00204 else if(placement == BOTTOM_RIGHT) 00205 { 00206 x = availRect.right() - width; 00207 y = availRect.bottom() - height; 00208 } 00209 //center 00210 else 00211 { 00212 x = availRect.left() + (availRect.width() - width) / 2; 00213 y = availRect.top() + (availRect.height() - height) / 2; 00214 } 00215 00216 //place window 00217 window.move( x, y ); 00218 } 00219 window.show(); 00220 00221 //load cursors 00222 loadCursors(); 00223 00224 //----------------------------------- 00225 //if this is a CVS build and cvsWarn set warn 00226 //user that application is potentially unstable! 00227 #ifdef CVS_CODE 00228 if( config->getBool ( "misc", "cvsWarn" ) ) 00229 { 00230 AlertDialog alert( "Warning! Unstable build!", 00231 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!"), 00232 "alertIcons/warning.png", &window ); 00233 alert.exec(); 00234 } 00235 #endif 00236 //----------------------------------- 00237 //if this is the first time the program is being run then show welcome screen 00238 WelcomeWindow* welcome; 00239 if(config->getBool( "misc", "firstRun" ) ) 00240 { 00241 welcome = new WelcomeWindow(); 00242 welcome->show(); 00243 centerWindow(welcome); 00244 config->setBool( "misc", "firstRun", false ); 00245 } 00246 //----------------------------------- 00247 return a.exec(); 00248 }
|