00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <qapplication.h>
00013 #include <qlayout.h>
00014 #include <qtranslator.h>
00015 #include <qtextcodec.h>
00016 #include <qdir.h>
00017 #include <iostream>
00018
00019
00020 #if defined(Q_OS_MACX)
00021 #include <CoreFoundation/CFURL.h>
00022 #include <CoreFoundation/CFBundle.h>
00023 #endif
00024
00025
00026
00027 #if defined(Q_OS_WIN)
00028 extern "C" long _ftol( double );
00029 extern "C" long _ftol2( double dblSource ) { return _ftol( dblSource ); }
00030
00031 #include <stdlib.h>
00032 #endif
00033
00034
00035 #include "gui/cursors.h"
00036 #include "gui/window.h"
00037 #include "gui/dialogs/alertDialog.h"
00038 #include "gui/welcomeWindow/welcomeWindow.h"
00039 #include "backend/tools/guiTools.h"
00040 #include "config.h"
00041 #include "configuration/configuration.h"
00042 #include "configuration/layoutSettingsWidget.h"
00043 #include "backend/tools/fileTools.h"
00044
00050 int main( int argc, char **argv)
00051 {
00052
00053 QApplication a(argc, argv);
00054
00055
00056
00057
00058
00059
00060
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
00067 #elif defined(Q_OS_WIN)
00068 MATERIAL_DIR = a.applicationDirPath();
00069
00070
00071 #else
00072 if( argc > 1 )
00073 {
00074
00075
00076 if( QString(argv[1]).contains(QString(BIN_DIR)) != 0 )
00077 { MATERIAL_DIR = DATA_DIR; }
00078
00079
00080
00081
00082 else
00083 { MATERIAL_DIR = QString(argv[1]); }
00084 }
00085
00086
00087 else
00088 MATERIAL_DIR = "./";
00089 #endif
00090
00091
00092
00093 IMAGE_PATH = MATERIAL_DIR + "/images/";
00094
00095
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
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
00108 THEMES_PATH = MATERIAL_DIR + "/themes/";
00109
00110
00111 XMLCONVERSION_PATH = MATERIAL_DIR + "/xmlConversion/";
00112
00113
00114
00115 if( !Configuration::constructSettingsDirectory() )
00116 {
00117 std::cout << "Error! Unable to make configurations directory!\n";
00118 return -1;
00119 }
00120
00121
00122
00123
00124
00125 bool tempDirMade = true;
00126 QDir homeDir;
00127
00128
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
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
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
00159 if(!tempDirMade)
00160 {
00161 std::cout << "Error! Unable to make temp files directory!\n";
00162 return -1;
00163 }
00164
00165
00166 QTranslator translator( 0 );
00167 translator.load( QString("AlbumShaper_") +
00168
00169 QTextCodec::locale(),
00170 MATERIAL_DIR + "/translations");
00171
00172 a.installTranslator( &translator );
00173
00174
00175 Window window;
00176 a.setMainWidget( &window );
00177
00178
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
00204 if(placement == TOP_LEFT)
00205 {
00206 x = availRect.left();
00207 y = availRect.top();
00208 }
00209
00210 else if(placement == TOP_RIGHT)
00211 {
00212 x = availRect.right() - width;
00213 y = availRect.top();
00214 }
00215
00216 else if(placement == BOTTOM_LEFT)
00217 {
00218 x = availRect.left();
00219 y = availRect.bottom() - height;
00220 }
00221
00222 else if(placement == BOTTOM_RIGHT)
00223 {
00224 x = availRect.right() - width;
00225 y = availRect.bottom() - height;
00226 }
00227
00228 else
00229 {
00230 x = availRect.left() + (availRect.width() - width) / 2;
00231 y = availRect.top() + (availRect.height() - height) / 2;
00232 }
00233
00234
00235 window.move( x, y );
00236 }
00237 window.show();
00238
00239
00240 loadCursors();
00241
00242
00243
00244
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
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 }