1*bb02e0acSNicolas Bonnefon /* 2*bb02e0acSNicolas Bonnefon * Copyright (C) 2009, 2010, 2011 Nicolas Bonnefon and other contributors 3*bb02e0acSNicolas Bonnefon * 4*bb02e0acSNicolas Bonnefon * This file is part of glogg. 5*bb02e0acSNicolas Bonnefon * 6*bb02e0acSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 7*bb02e0acSNicolas Bonnefon * it under the terms of the GNU General Public License as published by 8*bb02e0acSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 9*bb02e0acSNicolas Bonnefon * (at your option) any later version. 10*bb02e0acSNicolas Bonnefon * 11*bb02e0acSNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 12*bb02e0acSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 13*bb02e0acSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*bb02e0acSNicolas Bonnefon * GNU General Public License for more details. 15*bb02e0acSNicolas Bonnefon * 16*bb02e0acSNicolas Bonnefon * You should have received a copy of the GNU General Public License 17*bb02e0acSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 18*bb02e0acSNicolas Bonnefon */ 19*bb02e0acSNicolas Bonnefon 20*bb02e0acSNicolas Bonnefon #include <QApplication> 21*bb02e0acSNicolas Bonnefon 22*bb02e0acSNicolas Bonnefon #include <boost/program_options.hpp> 23*bb02e0acSNicolas Bonnefon namespace po = boost::program_options; 24*bb02e0acSNicolas Bonnefon 25*bb02e0acSNicolas Bonnefon #include <iostream> 26*bb02e0acSNicolas Bonnefon using namespace std; 27*bb02e0acSNicolas Bonnefon 28*bb02e0acSNicolas Bonnefon #include "persistentinfo.h" 29*bb02e0acSNicolas Bonnefon #include "sessioninfo.h" 30*bb02e0acSNicolas Bonnefon #include "configuration.h" 31*bb02e0acSNicolas Bonnefon #include "filterset.h" 32*bb02e0acSNicolas Bonnefon #include "recentfiles.h" 33*bb02e0acSNicolas Bonnefon #include "mainwindow.h" 34*bb02e0acSNicolas Bonnefon #include "savedsearches.h" 35*bb02e0acSNicolas Bonnefon #include "log.h" 36*bb02e0acSNicolas Bonnefon 37*bb02e0acSNicolas Bonnefon static void print_version(); 38*bb02e0acSNicolas Bonnefon 39*bb02e0acSNicolas Bonnefon int main(int argc, char *argv[]) 40*bb02e0acSNicolas Bonnefon { 41*bb02e0acSNicolas Bonnefon QApplication app(argc, argv); 42*bb02e0acSNicolas Bonnefon 43*bb02e0acSNicolas Bonnefon string filename = ""; 44*bb02e0acSNicolas Bonnefon 45*bb02e0acSNicolas Bonnefon TLogLevel logLevel = logWARNING; 46*bb02e0acSNicolas Bonnefon 47*bb02e0acSNicolas Bonnefon try { 48*bb02e0acSNicolas Bonnefon po::options_description desc("Usage: glogg [options] [file]"); 49*bb02e0acSNicolas Bonnefon desc.add_options() 50*bb02e0acSNicolas Bonnefon ("help,h", "print out program usage (this message)") 51*bb02e0acSNicolas Bonnefon ("version,v", "print glogg's version information") 52*bb02e0acSNicolas Bonnefon ("debug,d", "output more debug (include multiple times for more verbosity e.g. -dddd") 53*bb02e0acSNicolas Bonnefon ; 54*bb02e0acSNicolas Bonnefon po::options_description desc_hidden("Hidden options"); 55*bb02e0acSNicolas Bonnefon // For -dd, -ddd... 56*bb02e0acSNicolas Bonnefon for ( string s = "dd"; s.length() <= 10; s.append("d") ) 57*bb02e0acSNicolas Bonnefon desc_hidden.add_options()(s.c_str(), "debug"); 58*bb02e0acSNicolas Bonnefon 59*bb02e0acSNicolas Bonnefon desc_hidden.add_options() 60*bb02e0acSNicolas Bonnefon ("input-file", po::value<string>(), "input file") 61*bb02e0acSNicolas Bonnefon ; 62*bb02e0acSNicolas Bonnefon 63*bb02e0acSNicolas Bonnefon po::options_description all_options("all options"); 64*bb02e0acSNicolas Bonnefon all_options.add(desc).add(desc_hidden); 65*bb02e0acSNicolas Bonnefon 66*bb02e0acSNicolas Bonnefon po::positional_options_description positional; 67*bb02e0acSNicolas Bonnefon positional.add("input-file", 1); 68*bb02e0acSNicolas Bonnefon 69*bb02e0acSNicolas Bonnefon int command_line_style = (((po::command_line_style::unix_style ^ 70*bb02e0acSNicolas Bonnefon po::command_line_style::allow_guessing) | 71*bb02e0acSNicolas Bonnefon po::command_line_style::allow_long_disguise) ^ 72*bb02e0acSNicolas Bonnefon po::command_line_style::allow_sticky); 73*bb02e0acSNicolas Bonnefon 74*bb02e0acSNicolas Bonnefon po::variables_map vm; 75*bb02e0acSNicolas Bonnefon po::store(po::command_line_parser(argc, argv). 76*bb02e0acSNicolas Bonnefon options(all_options). 77*bb02e0acSNicolas Bonnefon positional(positional). 78*bb02e0acSNicolas Bonnefon style(command_line_style).run(), 79*bb02e0acSNicolas Bonnefon vm); 80*bb02e0acSNicolas Bonnefon po::notify(vm); 81*bb02e0acSNicolas Bonnefon 82*bb02e0acSNicolas Bonnefon if ( vm.count("help") ) { 83*bb02e0acSNicolas Bonnefon desc.print(cout); 84*bb02e0acSNicolas Bonnefon return 0; 85*bb02e0acSNicolas Bonnefon } 86*bb02e0acSNicolas Bonnefon 87*bb02e0acSNicolas Bonnefon if ( vm.count("version") ) { 88*bb02e0acSNicolas Bonnefon print_version(); 89*bb02e0acSNicolas Bonnefon return 0; 90*bb02e0acSNicolas Bonnefon } 91*bb02e0acSNicolas Bonnefon 92*bb02e0acSNicolas Bonnefon if ( vm.count( "debug" ) ) { 93*bb02e0acSNicolas Bonnefon logLevel = logINFO; 94*bb02e0acSNicolas Bonnefon } 95*bb02e0acSNicolas Bonnefon 96*bb02e0acSNicolas Bonnefon for ( string s = "dd"; s.length() <= 10; s.append("d") ) 97*bb02e0acSNicolas Bonnefon if ( vm.count( s ) ) 98*bb02e0acSNicolas Bonnefon logLevel = (TLogLevel) (logWARNING + s.length()); 99*bb02e0acSNicolas Bonnefon 100*bb02e0acSNicolas Bonnefon if ( vm.count("input-file") ) 101*bb02e0acSNicolas Bonnefon filename = vm["input-file"].as<string>(); 102*bb02e0acSNicolas Bonnefon } 103*bb02e0acSNicolas Bonnefon catch(exception& e) { 104*bb02e0acSNicolas Bonnefon cerr << "Option processing error: " << e.what() << endl; 105*bb02e0acSNicolas Bonnefon return 1; 106*bb02e0acSNicolas Bonnefon } 107*bb02e0acSNicolas Bonnefon catch(...) { 108*bb02e0acSNicolas Bonnefon cerr << "Exception of unknown type!\n"; 109*bb02e0acSNicolas Bonnefon } 110*bb02e0acSNicolas Bonnefon 111*bb02e0acSNicolas Bonnefon #if 0 112*bb02e0acSNicolas Bonnefon FILE* file = fopen("glogg.log", "w"); 113*bb02e0acSNicolas Bonnefon Output2FILE::Stream() = file; 114*bb02e0acSNicolas Bonnefon #endif 115*bb02e0acSNicolas Bonnefon 116*bb02e0acSNicolas Bonnefon FILELog::setReportingLevel( logLevel ); 117*bb02e0acSNicolas Bonnefon 118*bb02e0acSNicolas Bonnefon // Register the configuration items 119*bb02e0acSNicolas Bonnefon GetPersistentInfo().migrateAndInit(); 120*bb02e0acSNicolas Bonnefon GetPersistentInfo().registerPersistable( 121*bb02e0acSNicolas Bonnefon new SessionInfo, QString( "session" ) ); 122*bb02e0acSNicolas Bonnefon GetPersistentInfo().registerPersistable( 123*bb02e0acSNicolas Bonnefon new Configuration, QString( "settings" ) ); 124*bb02e0acSNicolas Bonnefon GetPersistentInfo().registerPersistable( 125*bb02e0acSNicolas Bonnefon new FilterSet, QString( "filterSet" ) ); 126*bb02e0acSNicolas Bonnefon GetPersistentInfo().registerPersistable( 127*bb02e0acSNicolas Bonnefon new SavedSearches, QString( "savedSearches" ) ); 128*bb02e0acSNicolas Bonnefon GetPersistentInfo().registerPersistable( 129*bb02e0acSNicolas Bonnefon new RecentFiles, QString( "recentFiles" ) ); 130*bb02e0acSNicolas Bonnefon 131*bb02e0acSNicolas Bonnefon // FIXME: should be replaced by a two staged init of MainWindow 132*bb02e0acSNicolas Bonnefon GetPersistentInfo().retrieve( QString( "settings" ) ); 133*bb02e0acSNicolas Bonnefon 134*bb02e0acSNicolas Bonnefon MainWindow* mw = new MainWindow(); 135*bb02e0acSNicolas Bonnefon 136*bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "MainWindow created."; 137*bb02e0acSNicolas Bonnefon mw->show(); 138*bb02e0acSNicolas Bonnefon mw->loadInitialFile( QString::fromStdString( filename ) ); 139*bb02e0acSNicolas Bonnefon return app.exec(); 140*bb02e0acSNicolas Bonnefon } 141*bb02e0acSNicolas Bonnefon 142*bb02e0acSNicolas Bonnefon static void print_version() 143*bb02e0acSNicolas Bonnefon { 144*bb02e0acSNicolas Bonnefon cout << "glogg " GLOGG_VERSION "\n"; 145*bb02e0acSNicolas Bonnefon #ifdef GLOGG_COMMIT 146*bb02e0acSNicolas Bonnefon cout << "Built " GLOGG_DATE " from " GLOGG_COMMIT "\n"; 147*bb02e0acSNicolas Bonnefon #endif 148*bb02e0acSNicolas Bonnefon cout << "Copyright (C) 2009, 2010, 2011 Nicolas Bonnefon and other contributors\n"; 149*bb02e0acSNicolas Bonnefon cout << "This is free software. You may redistribute copies of it under the terms of\n"; 150*bb02e0acSNicolas Bonnefon cout << "the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.\n"; 151*bb02e0acSNicolas Bonnefon cout << "There is NO WARRANTY, to the extent permitted by law.\n"; 152*bb02e0acSNicolas Bonnefon } 153