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 MATERIAL_DIR = QString(argv[1]).replace("/usr/bin", "/usr/share/albumshaper");
00074 else
00075 MATERIAL_DIR = "./";
00076 #endif
00077
00078
00079 IMAGE_PATH = MATERIAL_DIR + "/images/";
00080
00081
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
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
00094 THEMES_PATH = MATERIAL_DIR + "/themes/";
00095
00096
00097 XMLCONVERSION_PATH = MATERIAL_DIR + "/xmlConversion/";
00098
00099
00100
00101 if( !Configuration::constructSettingsDirectory() )
00102 {
00103 std::cout << "Error! Unable to make configurations directory!\n";
00104 return -1;
00105 }
00106
00107
00108
00109
00110
00111 bool tempDirMade = true;
00112 QDir homeDir;
00113
00114
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
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
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
00145 if(!tempDirMade)
00146 {
00147 std::cout << "Error! Unable to make temp files directory!\n";
00148 return -1;
00149 }
00150
00151
00152 QTranslator translator( 0 );
00153 translator.load( QString("AlbumShaper_") + QTextCodec::locale(), MATERIAL_DIR + "/translations");
00154 a.installTranslator( &translator );
00155
00156
00157 Window window;
00158 a.setMainWidget( &window );
00159
00160
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
00186 if(placement == TOP_LEFT)
00187 {
00188 x = availRect.left();
00189 y = availRect.top();
00190 }
00191
00192 else if(placement == TOP_RIGHT)
00193 {
00194 x = availRect.right() - width;
00195 y = availRect.top();
00196 }
00197
00198 else if(placement == BOTTOM_LEFT)
00199 {
00200 x = availRect.left();
00201 y = availRect.bottom() - height;
00202 }
00203
00204 else if(placement == BOTTOM_RIGHT)
00205 {
00206 x = availRect.right() - width;
00207 y = availRect.bottom() - height;
00208 }
00209
00210 else
00211 {
00212 x = availRect.left() + (availRect.width() - width) / 2;
00213 y = availRect.top() + (availRect.height() - height) / 2;
00214 }
00215
00216
00217 window.move( x, y );
00218 }
00219 window.show();
00220
00221
00222 loadCursors();
00223
00224
00225
00226
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
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 }