| 1 |
/*************************************************************************** |
| 2 |
main.cpp |
| 3 |
------------------- |
| 4 |
A brewing recipe calculator |
| 5 |
------------------- |
| 6 |
Copyright 1999-2008 David Johnson <[email protected]> |
| 7 |
All rights reserved. |
| 8 |
|
| 9 |
Redistribution and use in source and binary forms, with or without |
| 10 |
modification, are permitted provided that the following conditions |
| 11 |
are met: |
| 12 |
|
| 13 |
1. Redistributions of source code must retain the above copyright |
| 14 |
notice, this list of conditions and the following disclaimer. |
| 15 |
|
| 16 |
2. Redistributions in binary form must reproduce the above copyright |
| 17 |
notice, this list of conditions and the following disclaimer in the |
| 18 |
documentation and/or other materials provided with the distribution. |
| 19 |
|
| 20 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 |
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 |
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 |
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 |
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 |
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 |
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 |
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 |
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 |
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 |
****************************************************************************/ |
| 32 |
|
| 33 |
#include <cstdlib> |
| 34 |
|
| 35 |
#include <QApplication> |
| 36 |
#include <QLibraryInfo> |
| 37 |
#include <QLocale> |
| 38 |
#include <QMainWindow> |
| 39 |
#include <QStringList> |
| 40 |
#include <QTextStream> |
| 41 |
#include <QTranslator> |
| 42 |
|
| •43 |
#if defined(Q_OS_MAC) |
| 44 |
extern void qt_mac_set_menubar_icons(bool enable); |
| 45 |
#endif |
| 46 |
|
| 47 |
#include "qbrew.h"cxx . . $ `<file>/src/qbrew.h`/ |
| 48 |
#include "resource.h"cxx . . $ `<file>/src/resource.h`/ |
| 49 |
|
| 50 |
using namespace std; |
| 51 |
using namespace Resource; |
| 52 |
|
| 53 |
////////////////////////////////////////////////////////////////////////////// |
| 54 |
// doversion() |
| 55 |
// ----------- |
| 56 |
// Print out copyright and version info to stdout |
| 57 |
|
| 58 |
void doversioncxx . . $ doversion(be1a572b11f1967c).(QTextStreamcxx . . $ QTextStream# &stream) |
| 59 |
{ |
| 60 |
stream <<cxx . . $ QTextStream#`operator<<`(a8e98279dde0dccf). PACKAGEcxx . . $ `src/resource.h:39:9`! <<cxx . . $ QTextStream#`operator<<`(cff722283ca1c031). ' ' <<cxx . . $ QTextStream#`operator<<`(a8e98279dde0dccf). VERSIONcxx . . $ `src/resource.h:40:9`! <<cxx . . $ QTextStream#`operator<<`(cff722283ca1c031). '\n'; |
| 61 |
stream <<cxx . . $ QTextStream#`operator<<`(f61e69e0d177108f). QObjectcxx . . $ QObject#::trcxx . . $ QObject#tr(75d9f1c324b4579d).(DESCRIPTIONcxx . . $ Resource/DESCRIPTION.) <<cxx . . $ QTextStream#`operator<<`(cff722283ca1c031). '\n'; |
| 62 |
stream <<cxx . . $ QTextStream#`operator<<`(f61e69e0d177108f). QObjectcxx . . $ QObject#::trcxx . . $ QObject#tr(75d9f1c324b4579d).(COPYRIGHTcxx . . $ Resource/COPYRIGHT.); |
| 63 |
stream <<cxx . . $ QTextStream#`operator<<`(cff722283ca1c031). ' ' <<cxx . . $ QTextStream#`operator<<`(848b5dbd84829120). AUTHORcxx . . $ Resource/AUTHOR.; |
| 64 |
stream <<cxx . . $ QTextStream#`operator<<`(a8e98279dde0dccf). " <" <<cxx . . $ QTextStream#`operator<<`(848b5dbd84829120). AUTHOR_EMAILcxx . . $ Resource/AUTHOR_EMAIL. <<cxx . . $ QTextStream#`operator<<`(a8e98279dde0dccf). ">"; |
| 65 |
stream <<cxx . . $ `operator<<`(f27eeb5c966d2dd0). endlcxx . . $ QTextStreamFunctions/endl(e06208c9acdf85a).; |
| 66 |
} |
| 67 |
|
| 68 |
////////////////////////////////////////////////////////////////////////////// |
| 69 |
// dohelp() |
| 70 |
// -------- |
| 71 |
// Print out help info to stdout |
| 72 |
|
| 73 |
void dohelpcxx . . $ dohelp(be1a572b11f1967c).(QTextStreamcxx . . $ QTextStream# &stream) |
| 74 |
{ |
| 75 |
stream <<cxx . . $ QTextStream#`operator<<`(f61e69e0d177108f). QObjectcxx . . $ QObject#::trcxx . . $ QObject#tr(75d9f1c324b4579d).("Usage: %1 [options] [file]\n").argcxx . . $ QString#arg(bc823072288cbbb5).(PACKAGEcxx . . $ `src/resource.h:39:9`!); |
| 76 |
stream <<cxx . . $ QTextStream#`operator<<`(f61e69e0d177108f). QObjectcxx . . $ QObject#::trcxx . . $ QObject#tr(75d9f1c324b4579d).(DESCRIPTIONcxx . . $ Resource/DESCRIPTION.) <<cxx . . $ QTextStream#`operator<<`(a8e98279dde0dccf). "\n\n"; |
| 77 |
|
| 78 |
// arguments |
| 79 |
stream <<cxx . . $ QTextStream#`operator<<`(f61e69e0d177108f). QObjectcxx . . $ QObject#::trcxx . . $ QObject#tr(75d9f1c324b4579d).("Arguments\n"); |
| 80 |
stream <<cxx . . $ QTextStream#`operator<<`(f61e69e0d177108f). QObjectcxx . . $ QObject#::trcxx . . $ QObject#tr(75d9f1c324b4579d).(" file File to open") <<cxx . . $ QTextStream#`operator<<`(a8e98279dde0dccf). "\n\n"; |
| 81 |
|
| 82 |
// general options |
| 83 |
stream <<cxx . . $ QTextStream#`operator<<`(f61e69e0d177108f). QObjectcxx . . $ QObject#::trcxx . . $ QObject#tr(75d9f1c324b4579d).("Options\n"); |
| 84 |
stream <<cxx . . $ QTextStream#`operator<<`(f61e69e0d177108f). QObjectcxx . . $ QObject#::trcxx . . $ QObject#tr(75d9f1c324b4579d).(" --help Print the command line options.\n"); |
| 85 |
stream <<cxx . . $ QTextStream#`operator<<`(f61e69e0d177108f). QObjectcxx . . $ QObject#::trcxx . . $ QObject#tr(75d9f1c324b4579d).(" --version Print the application version.\n"); |
| 86 |
stream <<cxx . . $ `operator<<`(f27eeb5c966d2dd0). endlcxx . . $ QTextStreamFunctions/endl(e06208c9acdf85a).; |
| 87 |
} |
| 88 |
|
| 89 |
////////////////////////////////////////////////////////////////////////////// |
| 90 |
// doargs() |
| 91 |
// -------- |
| 92 |
// Process the arguments that QApplication doesn't take care of |
| 93 |
|
| 94 |
QStringcxx . . $ QString# doargscxx . . $ doargs(a8c14294abbeb95a).(QStringListcxx . . $ QStringList# arguments, QTextStreamcxx . . $ QTextStream# &stream) |
| 95 |
{ |
| 96 |
QStringcxx . . $ QString# argcxx . . $ QString#QString(ced63f7c635d850d).; |
| 97 |
for (int n=1; n<arguments.countcxx . . $ QList#count(455f465bc33b4cdf).(); ++n) { |
| 98 |
arg =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). arguments.atcxx . . $ QList#at(e2681f9bb6b2f357).(n); |
| 99 |
if ((arg ==cxx . . $ QString#`operator==`(7d4bdb1abc417636). "-h") || (arg ==cxx . . $ QString#`operator==`(7d4bdb1abc417636). "-help") || |
| 100 |
(arg ==cxx . . $ QString#`operator==`(7d4bdb1abc417636). "--help")) { |
| 101 |
dohelpcxx . . $ dohelp(be1a572b11f1967c).(stream); |
| 102 |
exit(0); |
| 103 |
} else if ((arg ==cxx . . $ QString#`operator==`(7d4bdb1abc417636). "-v") || (arg ==cxx . . $ QString#`operator==`(7d4bdb1abc417636). "-version") || |
| 104 |
(arg ==cxx . . $ QString#`operator==`(7d4bdb1abc417636). "--version")) { |
| 105 |
doversioncxx . . $ doversion(be1a572b11f1967c).(stream); |
| 106 |
exit(0); |
| 107 |
} else if (arg[cxx . . $ QString#`operator[]`(57436120916eb52c).0] ==cxx . . $ `operator==`(a468b2f18a3afe8). '-'cxx . . $ QChar#QChar(f349c77f591a7878).) { |
| 108 |
// no other valid options |
| 109 |
stream <<cxx . . $ QTextStream#`operator<<`(f61e69e0d177108f). QObjectcxx . . $ QObject#::trcxx . . $ QObject#tr(75d9f1c324b4579d).("Invalid parameter \"%1\"\n") .argcxx . . $ QString#arg(bc823072288cbbb5).(arg); |
| 110 |
dohelpcxx . . $ dohelp(be1a572b11f1967c).(stream); |
| 111 |
exit(1); |
| 112 |
} else { |
| 113 |
// it must be a filename |
| 114 |
return argcxx . . $ QString#QString(28715ad661ad3cec).; |
| 115 |
} |
| 116 |
} |
| 117 |
return (QObjectcxx . . $ QObject#::trcxx . . $ QObject#tr(75d9f1c324b4579d).(DEFAULT_FILEcxx . . $ Resource/DEFAULT_FILE.)); |
| 118 |
} |
| 119 |
|
| 120 |
////////////////////////////////////////////////////////////////////////////// |
| 121 |
// main() |
| 122 |
// ------ |
| 123 |
// Entry point of application |
| 124 |
|
| 125 |
int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) |
| 126 |
{ |
| 127 |
Q_INIT_RESOURCEcxx . . $ `<external>/15045578679651060896/qglobal.h:469:9`!(qbrew); |
| 128 |
|
| 129 |
QApplicationcxx . . $ QApplication# appcxx . . $ QApplication#QApplication(6e9b1c7df49e191d).(argc, argv); |
| 130 |
app.setApplicationNamecxx . . $ QCoreApplication#setApplicationName(3520e46b33348bf6).(PACKAGEcxx . . $ `src/resource.h:39:9`!); |
| 131 |
app.setOrganizationNamecxx . . $ QCoreApplication#setOrganizationName(3520e46b33348bf6).(TITLEcxx . . $ QString#QString(45672f3c6961a244).); |
| 132 |
|
| •133 |
#if defined(Q_OS_MAC) |
| 134 |
// disable icons on Mac menus (as is customary) |
| 135 |
qt_mac_set_menubar_icons(false); |
| 136 |
#endif |
| 137 |
|
| 138 |
// load qbrew translations |
| 139 |
QStringcxx . . $ QString# transdir = QBrewcxx . . $ QBrew#::instancecxx . . $ QBrew#instance(40173339d0c531b3).()->dataBasecxx . . $ QBrew#dataBase(4365c3963150523e).() +cxx . . $ operator+(3d22f08efddf8107). "translations"; |
| 140 |
QTranslatorcxx . . $ QTranslator# translatorcxx . . $ QTranslator#QTranslator(749de1b6ae65bddd).; |
| 141 |
if (translator.loadcxx . . $ QTranslator#load(142924642d8b819d).("qbrew_" +cxx . . $ operator+(c75c3ae4eb9af1a8). QLocalecxx . . $ QLocale#::systemcxx . . $ QLocale#system(7171962d3a2fd395).().namecxx . . $ QLocale#name(6ef7b6c27b00b43d).(), transdir)) { |
| 142 |
app.installTranslatorcxx . . $ QCoreApplication#installTranslator(d376406de50edad7).(&translator); |
| 143 |
} |
| 144 |
// load qt translations |
| 145 |
QStringcxx . . $ QString# qttransdir = QLibraryInfocxx . . $ QLibraryInfo#::locationcxx . . $ QLibraryInfo#location(dd7ac78f10b8a525).(QLibraryInfocxx . . $ QLibraryInfo#::TranslationsPathcxx . . $ QLibraryInfo#TranslationsPath.); |
| 146 |
QTranslatorcxx . . $ QTranslator# qttranslatorcxx . . $ QTranslator#QTranslator(749de1b6ae65bddd).; |
| 147 |
if (qttranslator.loadcxx . . $ QTranslator#load(142924642d8b819d).("qt_" +cxx . . $ operator+(c75c3ae4eb9af1a8). QLocalecxx . . $ QLocale#::systemcxx . . $ QLocale#system(7171962d3a2fd395).().namecxx . . $ QLocale#name(6ef7b6c27b00b43d).(), qttransdir)) { |
| 148 |
app.installTranslatorcxx . . $ QCoreApplication#installTranslator(d376406de50edad7).(&qttranslator); |
| 149 |
} |
| 150 |
|
| 151 |
// check for additional command line arguments |
| 152 |
QTextStreamcxx . . $ QTextStream# streamcxx . . $ QTextStream#QTextStream(65339a794c789c54).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!); |
| 153 |
QStringcxx . . $ QString# filename = doargscxx . . $ doargs(a8c14294abbeb95a).(app.argumentscxx . . $ QCoreApplication#arguments(669a05bc42dd57cc).(), stream); |
| 154 |
|
| 155 |
QBrewcxx . . $ QBrew#* mainwindow = QBrewcxx . . $ QBrew#::instancecxx . . $ QBrew#instance(40173339d0c531b3).(); |
| 156 |
mainwindow->initializecxx . . $ QBrew#initialize(3520e46b33348bf6).(filename); |
| 157 |
mainwindow->showcxx . . $ QWidget#show(49f6e7a06ebc5aa8).(); |
| 158 |
|
| 159 |
app.installEventFiltercxx . . $ QObject#installEventFilter(749de1b6ae65bddd).(mainwindow); // for handling file open events |
| 160 |
|
| 161 |
return app.execcxx . . $ QApplication#exec(b126dc7c1de90089).(); |
| 162 |
} |