Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

main.cpp

Go to the documentation of this file.
00001 //==============================================
00002 //  copyright            : (C) 2003 by Will Stokes
00003 //==============================================
00004 //  This program is free software; you can redistribute it 
00005 //  and/or modify it under the terms of the GNU General 
00006 //  Public License as published by the Free Software 
00007 //  Foundation; either version 2 of the License, or  
00008 //  (at your option) any later version.         
00009 //
00010 //  As a special exception, Will Stokes gives permission to 
00011 //  link this program with Qt non-commercial edition, and 
00012 //  distribute the resulting executable, without including the 
00013 //  source code for the Qt non-commercial edition in the 
00014 //  source distribution. 
00015 //==============================================
00016 
00017 //Systemwide includes
00018 #include <qapplication.h>
00019 #include <qlayout.h>
00020 #include <qtranslator.h>
00021 #include <qtextcodec.h>
00022 #include <qdir.h>
00023 
00024 #if defined(Q_OS_MACX)
00025 #include <CoreFoundation/CFURL.h>
00026 #include <CoreFoundation/CFBundle.h>
00027 #endif
00028 
00029 //Projectwide includes
00030 #include "gui/window.h"
00031 #include "config.h"
00032 
00038 #define DEFAULT_WIDTH 875
00039 #define DEFAULT_HEIGHT 620 
00040 
00041 int main( int argc, char **argv)
00042 { 
00043   //----------------------------------------------  
00044   //set material path
00045   
00046   //if using mac os x material dir in bundle
00047   #if defined(Q_OS_MACX)
00048   CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
00049   CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle);
00050   MATERIAL_DIR = QString( CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding())) + "/Contents/Resources";
00051   //otherwise material path can be passed in or assumed to be the local path
00052   #else
00053    if(argc > 1)
00054     MATERIAL_DIR = QString(argv[1]).replace("/usr/local/bin", "/usr/local/share/albumshaper");
00055   else
00056     MATERIAL_DIR = "./";
00057   #endif
00058   //----------------------------------------------  
00059   //set image path
00060   IMAGE_PATH = MATERIAL_DIR + "/images/";
00061   //----------------------------------------------  
00062   //set handbook path, attempt to use locale specific directory, otherwise fall back on english default
00063   HANDBOOK_PATH = MATERIAL_DIR + "/handbook_" + QTextCodec::locale() + "/";
00064   QDir handbookDir( HANDBOOK_PATH );
00065   if(!handbookDir.exists())
00066     HANDBOOK_PATH = MATERIAL_DIR + "/handbook/";
00067   //----------------------------------------------  
00068   //set text path, attempt to use locale specific directory, otherwise fall back on english default
00069   TEXT_PATH = MATERIAL_DIR + "/text_" + QTextCodec::locale() + "/";
00070   QDir textDir( TEXT_PATH );
00071   if(!textDir.exists())
00072     TEXT_PATH = MATERIAL_DIR + "/text/";
00073   //----------------------------------------------  
00074   //set themes path
00075   THEMES_PATH = MATERIAL_DIR + "/themes/";
00076   //----------------------------------------------  
00077   //set xml conversion path
00078   XMLCONVERSION_PATH = MATERIAL_DIR + "/xmlConversion/";
00079   //----------------------------------------------  
00080   //set easter eggs path
00081   EASTER_PATH = MATERIAL_DIR + "/easter/";
00082   //----------------------------------------------  
00083   //create app
00084   QApplication a(argc, argv);
00085 
00086   //create translator for current locale and attempt to install
00087   QTranslator translator( 0 );
00088   translator.load( QString("AlbumShaper_") + QTextCodec::locale(), MATERIAL_DIR + "/translations");
00089   a.installTranslator( &translator );
00090 
00091   //create main window and show  
00092   Window window;
00093   a.setMainWidget( &window );
00094   window.show();
00095 
00096   //----------------------------------------------  
00097   //determine default window size
00098   
00099   //set defaults
00100   int width = DEFAULT_WIDTH;
00101   int height = DEFAULT_HEIGHT;
00102   
00103   //if window size greater than desktop available then decrease
00104   QDesktopWidget *desktop = QApplication::desktop();
00105   if(width > desktop->width())
00106   { width = desktop->width(); }
00107   if(height > desktop->height())
00108   { height = desktop->height(); }
00109   
00110   //if window already must be larger than defaults then enlarge
00111   if(width < window.geometry().width())
00112   { width = window.geometry().width(); }
00113   if(height < window.geometry().height())
00114   { height = window.geometry().height(); }
00115   
00116   //compute offsets such that window centered on screen
00117   int xOffset = (desktop->width() - width) / 2;
00118   int yOffset = (desktop->height() - height) / 2;
00119   
00120   //set size and offset and show window
00121   window.setGeometry(xOffset, yOffset, width, height);
00122   window.repaint();
00123   return a.exec();  
00124 }

Generated on Thu Nov 13 00:10:53 2003 for AlbumShaper by doxygen 1.3.4